Change the treatment of falsy values in _.toQuery and _.fromQuery?
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- javascript
- Ambito
- web-dev
Direzione di ricerca
Inizia dai punti di ingresso _.toQuery e _.fromQuery ed esamina la discussione collegata della pull request. Decidi come devono essere mantenuti nel round-trip null, undefined, le stringhe vuote e lo zero numerico, incluso se si applicano le convenzioni di jQuery. Il lavoro è completato quando un comportamento concordato è documentato ed entrambe le funzioni hanno una copertura per i casi selezionati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
@yashshah1 pointed out a problem with _.toQuery and _.fromQuery: through stringification, falsy values are being "upgraded" to truthy if you encode them and then decode them again. For example, _.fromQuery(_.toQuery({a: null})) returns {a: 'null'}.
@yashshah1 proposed the following solution in https://github.com/documentcloud/underscore-contrib/pull/229#issuecomment-683548408:
What I am suggesting is a change in both
toQueryandfromQuery.Proposed behaviour:
_.toQuery('{ a: '', b: null, c: undefined, d: '10' }') // a=&b=&d=10 _.fromQuery('a=&b=&d=10') // { a: '', b: '', d: '10' }Reasoning
The idea is that toQuery and fromQuery need to be as complementary to each other as possible, one drawback that's seen already is that numbers need to be re-parsed. Wrt falsy values, however, I think there has to be a special provision as described above.What we gain by this is that null values are re-encoded as empty strings, which is falsy, and undefined isn't included in the object, which leads to almost the same usage in a few cases.
var obj = { a: '', b: null, c: undefined, d: '10' } console.log(obj['c']) // undefined obj = _.fromQuery(_.toQuery(obj)) console.log(obj['c']) // undefinedThis might lead to a change in the behaviour of
fromQueryand I am happy to raise a PR should this be acceptable.
I'm not sure whether this approach would be the right solution, for a couple of reasons:
- Information loss:
undefined,nulland the empty string''could no longer be distinguished. - What to do with numeric zero?
- How does this align with jQuery's encoding conventions?
However, this is something we can discuss. Let's do that here.
- Lingua principale
- JavaScript
- Stelle
- 622
- Fork
- 114
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
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 documentcloud/underscore-contrib
-
Boolean helperAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 38/100
documentcloud/underscore-contrib#254 · 2 commenti ·
-
breaking change bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
documentcloud/underscore-contrib#252 · 7 commenti ·
-
after modules enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
after modules docs enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
after modules enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 32/100
documentcloud/underscore-contrib#225 · 8 commenti ·
Tutte le issue di documentcloud/underscore-contrib
Issue simili
-
Daemon delete dialog: "Remove all ExApps" checkbox and `removeExApps` parameter have no effectAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 3 giorni
-
Add: Atlas TVApertachannels:add check:passed
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 4 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
jaegertracing/jaeger-ui#4547 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
feedback simulation workshop
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
githubnext/gh-aw-workshop#4090 ·
I maintainer di solito rispondono entro 1 giorno
-
bug deck: add to staging level: missing p-feature: Manage Submissions p-feature: Submissions and process priority: MUST HAVE ready for dev lead role: missing size: missing time sensitive
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
hackforla/tdm-calculator#3581 ·
I maintainer di solito rispondono entro 2 giorni