Accept custom characters for attributes name
See original GitHub issueBasic info:
- Node.js v10.13.0:
- jsdom 12.2.0:
Minimal reproduction case
const { JSDOM } = require("jsdom");
const dom = new JSDOM(`
<lazy-image src="path-to-src"></lazy-image>
`);
let document = dom.window.document;
let image = document.createElement('img');
image.setAttribute('[src]', 'placeholder-image');
// throws
UnhandledPromiseRejectionWarning: InvalidCharacterError: "[src]" did not match the Name production: Unexpected syntax in top
Line 1:
[src]
I know this is not a standard naming of attributes, but can the thrown exception in /node_modules/jsdom/lib/jsdom/living/nodes/Element-impl.js
line 240 become an optional
For example
setAttribute(name, value) {
try {
validateNames.name(name);
} catch(e) {
if (! allowCustomAttributeNaming) {
throw e;
}
}
...
}
The reason for this that i’m using Jsdom
for compiling html files and some times some attributes are exchanged with another ones.
Also elements could be duplicated with same attributes but with extra/minimal attributes.
Mainly i use [custom-attribute]
and (custom-event)
as attributes for any element so it would be easier to maintain it with same syntax.
How does similar code behave in browsers?
It is not rendered in the browser as the passed html to jsdom
is not being displayed directly to the browser.
The code is transformed to dom elements
so the passed code will be handled only by the dom compiler.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
What characters are allowed in an HTML attribute name?
Attribute names must consist of one or more characters other than the space characters, U+0000 NULL, U+0022 QUOTATION MARK ("), U+0027 ...
Read more >Relaxing restrictions on custom attribute names - HTML - WICG
Custom attribute names must contain a hyphen; The prefix must be at least 2 characters long; The prefix must not be in the...
Read more ><input>: The Input (Form Input) element - HTML
A control that lets the user select a file. Use the accept attribute to define the types of files that the control can...
Read more >Custom attributes in JavaScript | Trepachev Dmitry - code.mu
HTML allows you to add your own custom attributes to tags. Such attributes should start with data- followed by whatever attribute name you...
Read more >Custom Object Name attribute limited to 80 char | Clarity
I agree to all the answers posted above. There is a Description field as you should be aware, where more characters can be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m using jsdom to generate DOM tree in node without browser.
There is browser’s supported custom attribute names like ‘–smth’ for generated html code (not for setAttribute, yes).
Monkeypatch for this:
+1 for adding this as an option - perhaps in the JSDOM constructor options?
I ran into this issue while trying to use JSDOM as a code-generator to produce PWA code (Angular, React, etc) from a collection of templates.