8000 fix: initialize form serialization before appending fields by xunguangzlj-cloud · Pull Request #546 · hmjz100/LinkSwift · GitHub
[go: up one dir, main page]

Skip to content

fix: initialize form serialization before appending fields - #546

Open
xunguangzlj-cloud wants to merge 1 commit into
hmjz100:devfrom
xunguangzlj-cloud:fix/form-encoding-prefix
Open

xunguangzlj-cloud wants to merge 1 commit into
hmjz100:devfrom
xunguangzlj-cloud:fix/form-encoding-prefix

Conversation

@xunguangzlj-cloud
Copy link
Copy Markdown

Summary

Initialize base.stringify with an empty string before appending form fields. The Baidu authorization POST in getToken() uses this helper: its first grant_permissions_arr field was encoded as undefinedgrant_permissions_arr, because str started as undefined. An empty form (or one containing only empty arrays) also threw when calling str.slice().

The production fix is one line. Existing URI encoding, repeated array fields, field order and exclusion of inherited properties remain unchanged.

Validation

  • node --test tests/stringify.test.cjs: 9 passed. The tests extract and execute the actual method from the distributed userscript; no copy of the algorithm is maintained.
  • Pointing LINKSWIFT_SOURCE at unchanged dev (c62d10a3071b089c6ffef4e9fa56f05bbb03079c) makes the same 9 tests fail.
  • Includes the actual authorization permission-field shape, empty forms/arrays, Unicode/reserved characters, repeated values, and inherited-property controls.
  • npx --no-install eslint .: 0 errors, retaining the existing two unused-variable warnings (items, token).
  • node --check on the main userscript and git diff --check: passed.

npm test is currently the repository's fixed failing placeholder (Error: no test specified); this PR leaves that unrelated script unchanged and uses the explicit Node test command above. Tests use no credentials or network access. A live Baidu account/authorization session has not been exercised, so this verifies the request-body encoding rather than claiming end-to-end OAuth success.

Targets dev as required by the contribution guide. No userscript version or dependency changes. Prepared with AI assistance under the account owner's direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0