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.

querySelectorAll fails with single character attributes

See original GitHub issue

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
...

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
dperinicommented, Mar 31, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What chars needs escaping in querySelector? - Stack Overflow
The thing is Im making a firefox addon Im doing is identifying items by the attribute in label (cuz class is same for...
Read more >
Element.querySelectorAll() - Web APIs | MDN
The Element method querySelectorAll() returns a static (not live) NodeList representing a list of elements matching the specified group of ...
Read more >
HTML DOM querySelectorAll() Method - W3Schools
Specifies one or more CSS selectors to match the element. These are used to select HTML elements based on their id, classes, types,...
Read more >
Element.querySelectorAll()
This method is implemented based on the ParentNode mixin's querySelectorAll() method. · Characters which are not part of standard CSS syntax must ...
Read more >
What to do when querySelector() fail on valid selectors
Lots of special characters are valid for IDs, classes, and names. You can use square brackets ( [] ) or curly brackets (...
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