Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parseSitemap and parseSitemapIndex uncatchable errors #375

Merged
merged 1 commit into from
Dec 31, 2021

Conversation

huntharo
Copy link
Contributor

@huntharo huntharo commented Nov 8, 2021

  • parseSitemap and parseSitemapIndex both have an issue where errors in the _transform function are not catchable by the caller and instead result in an Unhandled error.
  • The file that causes this problem was written with sitemap.js but it's not yet clear if the malformed file indicates that there is another bug to be fixed or if that is more indicative of a problem in my consumption of the library. More to follow on that if I find another issue.
  • Added a test that fails before the fix and that passes after the fix

Before Fix - Output

The output below would result if parseSitemapIndex or parseSitemap were called on a malformed XML file that has an unescaped < in the text of a tag.

 FAIL  tests/sitemap-index-parser.test.ts
  ● parseSitemapIndex › rejects malformed file

    Unhandled error. (Error: Unencoded <
    Line: 10
    Column: 25
    Char: <

      127 |     // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      128 |     // @ts-ignore
    > 129 |     this.saxStream.write(data, encoding);
          |                    ^
      130 |     callback();
      131 |   }
      132 | }

      at error (node_modules/sax/lib/sax.js:651:10)
      at strictFail (node_modules/sax/lib/sax.js:677:7)
      at SAXParser.write (node_modules/sax/lib/sax.js:1080:13)
      at SAXStream.write (node_modules/sax/lib/sax.js:239:18)
      at XMLToSitemapIndexStream._transform (lib/sitemap-index-parser.ts:129:20)
      Line: 10
      Column: 25
      Char: <
      at error (node_modules/sax/lib/sax.js:651:10)
      at strictFail (node_modules/sax/lib/sax.js:677:7)
      at SAXParser.write (node_modules/sax/lib/sax.js:1080:13)
      at SAXStream.write (node_modules/sax/lib/sax.js:239:18)
      at XMLToSitemapIndexStream._transform (lib/sitemap-index-parser.ts:129:20)
      at SAXParser.SAXStream._parser.onerror (node_modules/sax/lib/sax.js:194:10)
      at emit (node_modules/sax/lib/sax.js:624:35)
      at error (node_modules/sax/lib/sax.js:653:5)
      at strictFail (node_modules/sax/lib/sax.js:677:7)
      at SAXParser.write (node_modules/sax/lib/sax.js:1080:13)
      at SAXStream.write (node_modules/sax/lib/sax.js:239:18)
      at XMLToSitemapIndexStream._transform (lib/sitemap-index-parser.ts:129:20)

@derduher derduher merged commit daa2a94 into ekalinin:master Dec 31, 2021
@derduher
Copy link
Collaborator

Thank you for the quality submission

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants