jsdom: querySelectorAll fails with single character attributes

I have a document fragment that I’m testing which contains the following code:

<h1 t="construction.title">Pardon the potholes, site is under construction</h1>

I’m using the i18n plugin in my project, and therefore the t attribute is used to flag down the title of what we are going to translate (it’s the key to use).
When I use window.document.querySelectorAll('[t]');, I get an error

SyntaxError
    at DocumentImpl.<anonymous> (/Users/astoker/Documents/Github/AStoker/astoker.github.io/node_modules/jsdom/lib/jsdom/living/nodes/ParentNode-impl.js:83:11)
    at DocumentImpl.querySelectorAll (/Users/astoker/Documents/Github/AStoker/astoker.github.io/node_modules/jsdom/lib/jsdom/utils.js:133:45)
    at Document.querySelectorAll (/Users/astoker/Documents/Github/AStoker/astoker.github.io/node_modules/jsdom/lib/jsdom/living/generated/ParentNode.js:39:62)
    at eval (eval at evaluate (:117:21), <anonymous>:1:22)
    at Object.done (/Users/astoker/Documents/Github/AStoker/astoker.github.io/aurelia_project/tasks/process-locales.js:54:57)
    at process.nextTick (/Users/astoker/Documents/Github/AStoker/astoker.github.io/node_modules/jsdom/lib/jsdom.js:320:18)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickDomainCallback (internal/process/next_tick.js:122:9)

This works fine when I use the i18n attribute window.document.querySelectorAll('[i18n]');. Not sure what is going on… What I’m doing. Using gulp to go through files, and the files are all html fragments wrapped in <template> tags.

jsdom.env(
                    `<html><body>${file.contents.toString()}</body></html>`, //Wrapping in html/body for fragments to be loaded
                    function(err, window) {
                        if (err) {
                            console.log('Trouble making the window for scraping');
                            console.log(err);
                        }
                        //Create "Template" in body
                        let t = window.document.querySelector('template');
                        let tInstance = window.document.importNode(t.content, true);
                        window.document.body.appendChild(tInstance);

                        //Other strange bug with querySelectorAll and passing multiple selectors (querySelectorAll('[i18n], [t]');). So we're going to make two seperate calls
                        let i18nElements = window.document.querySelectorAll('[i18n]'); //Works
                        let tElements = window.document.querySelectorAll('[t]'); //Fails
...

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

@AStoker I was trying to add other tweaks but failed … I will try once more with those tweaks next week. Then I will release 1.4.0, after few more testing.