question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lower case doctype is not recognised

See original GitHub issue

(Thanks so much for the library, it’s awesome. I’m particularly appreciative that it’s very flexible about the input, except in this case…)

Describe the bug

Lower case “doctype” is not supported, although it’s valid in HTML.

To Reproduce

Any input with doctype as lowercase not upper case:

const fs = require('fs')
const { SaxEventType, SAXParser } = require('sax-wasm')

const saxWasmBuffer = fs.readFileSync(require.resolve('sax-wasm/lib/sax-wasm.wasm'))

const get_type = (t) => {
  for (const [name, value] of Object.entries(SaxEventType)) {
    if (t === value) {
      return name
    }
  }
}
const str2array = (str) => new Uint8Array(Buffer.from(str, 'utf8'))

// Instantiate
const options = {highWaterMark: 32 * 1024}
const parser = new SAXParser(SaxEventType.Attribute | SaxEventType.CloseTag | SaxEventType.OpenTag | SaxEventType.Text | SaxEventType.Doctype, options)
parser.eventHandler = (event, data) => {
  console.log(`${get_type(event)}:`, data.toJSON())
}

parser.prepareWasm(saxWasmBuffer).then(() => {
  console.log('lower case:')
  parser.write(str2array('<!doctype html>'))
  parser.end()
  console.log('upper case:')
  parser.write(str2array('<!DOCTYPE html>'))
  parser.end()
})

This prints nothing for the first case but does find the DOCTYPE clause for the second case.

I think the problem might be:

https://github.com/justinwilaby/sax-wasm/blob/90c09fd91ea1485244b9a6bf422a7595c91316b3/src/sax/parser.rs#L259

which appears to require "DOCTYPE"

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
justinwilabycommented, May 18, 2021

Understood, I should be able to get to this shortly.

0reactions
samuelcolvincommented, May 20, 2021

Thanks so much for resolving this, I’ve upgraded and tests are passing!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uppercase or lowercase doctype? - html - Stack Overflow
In both cases it is declared as the fixed string "DOCTYPE" (which is not a tag, it is a keyword). So in the...
Read more >
Why is "DOCTYPE" uppercase but "html" lower?
The thing to keep in mind is that the document type declararation is not HTML or XML. It is SGML, the parent schema...
Read more >
Bug: "doctype" in lowercase is not recognized - Mailing lists
I tried two (valid) HTML 4.01 files, whose only difference is that "DOCTYPE" is uppercase in one and lowercase in the other.
Read more >
DOCTYPE does not need to be capitalized · Issue #17552
The ! and uppercase DOCTYPE is important, especially for older browsers. The html is not case sensitive. This statement isn't accurate.
Read more >
A 3-Minute Guide to Doctype HTML - HubSpot Blog
The <!DOCTYPE> declaration is not case sensitive. Although most commonly written in all uppercase, you can write it as lowercase, sentence case, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found