spreadAttributes()/optionalAttribute(): update() passes HTML encoded values to setAttribute(), client attributes differ from the server rendered ones
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 84/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript
- Ambito
- frontend
Direzione di ricerca
Inizia con SpreadAttributesDirective.update() e OptionalAttributeDirective.update() nei file sorgente delle direttive, poi leggi src/util/AttributeParser.js e il test indicato test/unit/directive-spread-attributes.test.js. Verifica entrambe le direttive con valori stringa e JSON, inclusi i casi di accettazione. Il lavoro è completo quando gli attributi client corrispondono all'output analizzato di toString() e l'output di toString() rimane invariato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Goal
An attribute set by spreadAttributes() or optionalAttribute() has the same value after a client render as after parsing the toString() output: the value as passed, JSON for non-strings, without character references.
Context
Found while looking at #192. update() runs the value through encodeAttribute() and passes the result to setAttribute(). setAttribute() takes its argument as the value and does not parse character references, so they end up in the attribute literally. In stringify() the same encoding is right, there the HTML parser decodes it.
const el = document.createElement('a');
new SpreadAttributesDirective(el).update({ href: '/a?b=1&c=2', title: 'a "b" <c>', list: [1, '2'] });
el.getAttribute('href'); // 1.3.0: '/a?b=1&c=2' expected: '/a?b=1&c=2'
el.getAttribute('title'); // 1.3.0: 'a "b" <c>' expected: 'a "b" <c>'
el.getAttribute('list'); // 1.3.0: '[1,"2"]' expected: '[1,"2"]'
new OptionalAttributeDirective(el).update(true, 'href', '/a?b=1&c=2') sets /a?b=1&c=2 the same way.
What follows from it:
- A spread
hrefwith more than one query parameter points to a different URL on the client, the second parameter is namedamp;c. - Text attributes (
title,aria-label,alt,placeholder) carry the character references as text. - A JSON value is no JSON anymore:
parseAttribute('[1,"2"]')returns the string,parseAttribute('[1,"2"]')returns the array. - The
toString()output of the same template parses to the unencoded values, so the server rendered attributes and the client rendered ones disagree.
Plain attribute bindings are not affected, AttributePart passes the value to setAttribute() as it is. decodeAttribute() exists in src/util/AttributeParser.js, nothing calls it.
test/unit/directive-spread-attributes.test.js asserts the encoded value on the client (el.getAttribute('list') equals '[1,"2",3]'), the current behaviour is pinned by that test.
Acceptance criteria
- After
new SpreadAttributesDirective(el).update({ href: '/a?b=1&c=2' }),el.getAttribute('href')is/a?b=1&c=2. - After
update({ list: [1, '2'] }),JSON.parse(el.getAttribute('list'))deep equals[1, '2']. - Same for
OptionalAttributeDirective.update(true, name, value). - For a template with either directive, the attribute values after a client render equal the ones after parsing its
toString()output. - The
toString()output does not change.
Proposal (non-binding)
Drop encodeAttribute() from both update() methods and pass the string, or the JSON string for non-strings, to setAttribute(). The client assertions in the directive tests change with it. The changelog names it, the attribute values on the client change for anyone who reads them.
Out of scope
- Quoting in
stringify(), that is #193. - Omitting
undefined/null/NaNvalues instringify(), that is #192.
- Lingua principale
- JavaScript
- Stelle
- 30
- Fork
- 5
- Merge medio
- 1h 57m
- PR unite (30g)
- 10
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di webtides/element-js
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
webtides/element-js#201 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
webtides/element-js#198 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
webtides/element-js#193 ·
I maintainer di solito rispondono entro 1 giorno
-
[RENDERER]: only the first raw text element with interpolations is handled, a line break inside one breaks it tooForse già presa @eddyloewen l’ha presa 28 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
webtides/element-js#185 ·
I maintainer di solito rispondono entro 1 giorno
-
[RENDERER]: a line break at the start of a <textarea> differs between toString() and a client renderAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 58/100
webtides/element-js#200 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di webtides/element-js
Issue simili
-
area:testing bug effort:low model:light plan planner:gpt-6-2-sol tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
Agent360dk/browser-mcp#124 ·
I maintainer di solito rispondono entro 2 giorni
-
area:site feature good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
pacocartones/free-llm-api-hub#829 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
Jason-Vaughan/TangleClaw#3270 ·
I maintainer di solito rispondono entro 1 giorno