appendQueryString should combine duplicates or error if different
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 30/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript
- Ambito
- tooling
Direzione di ricerca
The proposed changes are in js/QueryStringMachine.js and js/QueryStringMachineTests.js; first read the existing appendQueryString implementation and run the current test file. Define the duplicate-key behavior for identical and differing values, then add tests covering it and finish when the documented behavior passes without regressing existing URL appending cases.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
@samreid and I thought that this would be a nice improvement since QSM errors out if you supply a query parameter twice. We got a bit stuck though and have to give up right now. Here is a patch!
Index: js/QueryStringMachine.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- js/QueryStringMachine.js (revision d0435aa45cc13c17aa1c8c9c21882539123249db)
+++ js/QueryStringMachine.js (date 1581717644317)
@@ -311,7 +311,32 @@
* // Limit to the second screen
* simURL = QueryStringMachine.appendQueryString( simURL, 'screens=2' );
*/
- appendQueryString: function( url, queryParameters ) {
+ appendQueryString: function( url, queryParameters, options ) {
+
+ options = options || {
+ combineDuplicates: true
+ };
+
+
+ const convertToSearchURI = queryString => {
+ if ( queryString.indexOf( '?' ) === 0 ) {
+ return queryString;
+ }
+ else if ( queryString( '&' ) === 0 ) {
+ return `?${queryString.substring( 1 )}`;
+ }
+ else {
+ return `?${queryString}`;
+ }
+ };
+
+ let allParametersForURL = [];
+ if ( url.indexOf( '?' ) > 0 ) {
+ debugger;
+ allParametersForURL = getKeysForString( `?${url.split( '?' )[ 1 ]}` );
+ }
+ let allParametersFromQueryParameters = getKeysForString( convertToSearchURI( queryParameters ) );
+
if ( queryParameters.indexOf( '?' ) === 0 || queryParameters.indexOf( '&' ) === 0 ) {
queryParameters = queryParameters.substring( 1 );
}
@@ -400,6 +425,23 @@
return values;
};
+ /**
+ * Query strings may show the same key appearing multiple times, such as ?value=2&value=3.
+ * This method recovers all of the string values. For this example, it would be ['2','3'].
+ *
+ * @param {string} string - the parameters string (including first '?')
+ * @returns {Array.<string>} -
+ */
+ const getKeysForString = function( string ) {
+ const keys = [];
+ const params = string.slice( 1 ).split( '&' );
+ for ( let i = 0; i < params.length; i++ ) {
+ const splitByEquals = params[ i ].split( '=' );
+ keys.push( splitByEquals[ 0 ] );
+ }
+ return keys;
+ };
+
// Schema validation ===============================================================================================
/**
@@ -667,7 +709,7 @@
* validValues - array of the valid values for the query parameter
* isValidValue - function that takes a parsed Object (not string) and checks if it is acceptable
* elementSchema - specifies the schema for elements in an array
- * separator - array elements are separated by this string, defaults to `,`
+ * separator - array elements are separated by this string, defaults to `, `
* parse - a function that takes a string and returns an Object
*/
const TYPES = {
Index: js/QueryStringMachineTests.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- js/QueryStringMachineTests.js (revision d0435aa45cc13c17aa1c8c9c21882539123249db)
+++ js/QueryStringMachineTests.js (date 1581715948637)
@@ -202,5 +202,20 @@
test( 'http://localhost.com/hello.html?abc', '', 'http://localhost.com/hello.html?abc' );
test( 'http://localhost.com/hello.html?abc', '?123', 'http://localhost.com/hello.html?abc&123' );
test( 'http://localhost.com/hello.html?abc', '&123', 'http://localhost.com/hello.html?abc&123' );
+
+
+ const combineDuplicates = {
+ combineDuplicates: true
+ };
+
+ test( 'http://localhost.com/hello.html?abc&123', '&123', 'http://localhost.com/hello.html?abc&123', combineDuplicates );
+
+
+ assert.throws( () => {
+ QueryStringMachine.appendQueryString( 'http://localhost.com/hello.html?abc', 'abc=3', combineDuplicates )
+ }, 'duplicate parameter is not identical' );
+
+ // without combineDuplicates option, just allow multiple query parameters.
+ test( 'http://localhost.com/hello.html?abc', 'abc=3', 'http://localhost.com/hello.html?abc&abc=3' );
} );
} );
\ No newline at end of file
- Lingua principale
- TypeScript
- Stelle
- 3
- Fork
- 5
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
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 phetsims/query-string-machine
-
type:epic
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
phetsims/query-string-machine#51 · 2 commenti ·
-
Replace query-parameter spreadsheet with "ask the sim".Forse di nuovo libera @zepumph l’ha presa 561 giorni fa e non c’è nessuna pull request aperta. Apertapriority:5-deferred
phetsims/query-string-machine#46 · 6 commenti · 2 assegnatari ·
-
dev:code-review
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
phetsims/query-string-machine#43 · 10 commenti ·
-
type:misc
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
phetsims/query-string-machine#36 · 2 commenti ·
-
Convert booleans with defaultValue:false to flags.Forse di nuovo libera @jonathanolson l’ha presa 3271 giorni fa e non c’è nessuna pull request aperta. Aperta
phetsims/query-string-machine#29 · 8 commenti · 1 assegnatario ·
Tutte le issue di phetsims/query-string-machine
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
vercel/streamdown#673 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
docs(stream-protocol): document messageMetatadata on start/finish and the message-metadata chunkApertafactory-active task-identify-harness-labels-done task-identify-issue-type-done
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
vercel/ai#23375 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
agilepathway/label-checker#721 ·
I maintainer di solito rispondono entro 1 giorno
-
CLI Empathy needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
chromaui/chromatic-cli#1524 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno