Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Commit

Permalink
Add support for port number and IPv4 addresses in 'baseURL' global op…
Browse files Browse the repository at this point in the history
…tion (#5)
  • Loading branch information
cheap-glitch committed Feb 3, 2020
1 parent 67688eb commit 20d77d3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions src/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,16 @@ const optionsValidator = ajv.compile({

anyOf: [
{
minLength: 0,
maxLength: 0,
minLength: 0,
maxLength: 0,
},
{
format: 'uri',
pattern: '\\.[a-z]+$',
}
format: 'uri',
pattern: '\\.[a-z]+(?::\\d{1,4})?$',
},
{
pattern: '^https?:\\/\\/(?:\\d{1,3}\\.){3}\\d{1,3}(?::\\d{1,4})?$',
},
]
},
trailingSlash: {
Expand Down
14 changes: 14 additions & 0 deletions test/sitemap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ describe("single sitemap generation", () => {
})).to.deep.equal(wrapSitemap(
'<url><loc>https://website.net</loc></url><url><loc>https://website.net/about</loc></url>'
));

expect(await generate({
baseURL: 'https://website.net:7000',
urls: ['/', '/about'],
})).to.deep.equal(wrapSitemap(
'<url><loc>https://website.net:7000</loc></url><url><loc>https://website.net:7000/about</loc></url>'
));

expect(await generate({
baseURL: 'https://162.75.90.1',
urls: ['/', '/about'],
})).to.deep.equal(wrapSitemap(
'<url><loc>https://162.75.90.1</loc></url><url><loc>https://162.75.90.1/about</loc></url>'
));
});

it("removes trailing slashes", async () => {
Expand Down
19 changes: 12 additions & 7 deletions test/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ describe("the validation of the options returns an error when:", () => {
expect(validate({ outputDir: './sitemap' })).to.be.true;
});

it("'baseURL' is not a proper URI", () => {
expect(validate({ baseURL: 'not an URI' })).to.be.false;
expect(validate({ baseURL: 'somedomain.wtf' })).to.be.false;
expect(validate({ baseURL: 'https://missing-something' })).to.be.false;

expect(validate({ baseURL: 'https://domain.fr' })).to.be.true;
expect(validate({ baseURL: 'http://www.other-domain.fr' })).to.be.true;
it("'baseURL' is not a proper URI or IPv4 address", () => {
expect(validate({ baseURL: 'not an URI' })).to.be.false;
expect(validate({ baseURL: 'somedomain.wtf' })).to.be.false;
expect(validate({ baseURL: 'https://missing-something' })).to.be.false;
expect(validate({ baseURL: '127.0' })).to.be.false;

expect(validate({ baseURL: 'https://domain.fr' })).to.be.true;
expect(validate({ baseURL: 'http://www.other-domain.fr' })).to.be.true;
expect(validate({ baseURL: 'http://www.website.com:8080' })).to.be.true;
expect(validate({ baseURL: 'https://webapp.com:27' })).to.be.true;
expect(validate({ baseURL: 'https://127.0.0.1' })).to.be.true;
expect(validate({ baseURL: 'https://127.0.0.1:8000' })).to.be.true;
});

describe("the default URL meta tags are invalid, because", () => {
Expand Down

0 comments on commit 20d77d3

Please sign in to comment.