Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/sitemap-index-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ export class XMLToSitemapIndexStream extends Transform {
encoding: string,
callback: TransformCallback
): void {
// correcting the type here can be done without making it a breaking change
// TODO fix this
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this.saxStream.write(data, encoding);
callback();
try {
// correcting the type here can be done without making it a breaking change
// TODO fix this
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this.saxStream.write(data, encoding);
callback();
} catch (error) {
callback(error);
}
}
}

Expand Down
16 changes: 10 additions & 6 deletions lib/sitemap-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,16 @@ export class XMLToSitemapItemStream extends Transform {
encoding: string,
callback: TransformCallback
): void {
// correcting the type here can be done without making it a breaking change
// TODO fix this
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this.saxStream.write(data, encoding);
callback();
try {
// correcting the type here can be done without making it a breaking change
// TODO fix this
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this.saxStream.write(data, encoding);
callback();
} catch (error) {
callback(error);
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/mocks/index-unescaped-lt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://www.example.com/sitemap1.xml.gz</loc>
<lastmod>2004-10-01T18:23:17+00:00</lastmod>
</sitemap>
<sitemap>
<loc>https://www.example.com/sitemap2.xml.gz</loc>
<lastmod>2005-01-01<</lastmod>
</sitemap>
</sitemapindex>
12 changes: 12 additions & 0 deletions tests/mocks/unescaped-lt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>http://example.com&amp;&gt;&lt;'"/</loc>
<lastmod>2011-06-27T00:00:00.000Z</lastmod>
<changefreq>always<</changefreq>
<priority>0.9</priority>
<image:image>
<image:loc>http://urltest.com&amp;&gt;&lt;'"/</image:loc>
</image:image>
</url>
</urlset>
10 changes: 10 additions & 0 deletions tests/sitemap-index-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ describe('parseSitemapIndex', () => {
);
expect(urls).toEqual(normalizedSample.sitemaps);
});

it('rejects malformed file', async () => {
await expect(async () =>
parseSitemapIndex(
createReadStream(resolve(__dirname, './mocks/index-unescaped-lt.xml'), {
encoding: 'utf8',
})
)
).rejects.toThrow();
});
});

describe('XMLToSitemapIndexItemStream', () => {
Expand Down
10 changes: 10 additions & 0 deletions tests/sitemap-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ describe('parseSitemap', () => {
);
expect(urls).toEqual(normalizedSample.urls);
});

it('rejects malformed file', async () => {
await expect(async () =>
parseSitemap(
createReadStream(resolve(__dirname, './mocks/unescaped-lt.xml'), {
encoding: 'utf8',
})
)
).rejects.toThrow();
});
});

describe('XMLToSitemapItemStream', () => {
Expand Down