appendQueryString should combine duplicates or error if different
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 30/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- tooling
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
@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
- 主要语言
- TypeScript
- 星标
- 3
- 派生
- 5
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
phetsims/query-string-machine 的其他 Issue
-
type:epic
难度 5/5 一周以上 新手友好度 20/100
phetsims/query-string-machine#51 · 2 条评论 ·
-
Replace query-parameter spreadsheet with "ask the sim".可能重新可做 @zepumph 于 572 天前认领,目前没有进行中的 PR。 未关闭priority:5-deferred
phetsims/query-string-machine#46 · 6 条评论 · 已指派 2 人 ·
-
dev:code-review
难度 4/5 3-5 天 新手友好度 30/100
phetsims/query-string-machine#43 · 10 条评论 ·
-
type:misc
难度 3/5 1-2 天 新手友好度 25/100
phetsims/query-string-machine#36 · 2 条评论 ·
-
Convert booleans with defaultValue:false to flags.可能重新可做 @jonathanolson 于 3282 天前认领,目前没有进行中的 PR。 未关闭
phetsims/query-string-machine#29 · 8 条评论 · 已指派 1 人 ·
查看 phetsims/query-string-machine 的全部 Issue
相似的 Issue
-
a10y a10y-audit ai-driven-qa claude
难度 2/5 1-3 小时 新手友好度 86/100
linagora/twake-directory-manager#219 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
type: bug
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 1 天内回复
-
0️⃣ phase/new
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
Pulse v7: buildPreferencesFromTelos() bypasses telosSectionOrFile(), renders empty on unified-TELOS installs可能已有人在做 @zephyr91 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
danielmiessler/LifeOS#2393 ·
维护者通常 4 天内回复