Skip to content

Form-decode google search queries before the plus swap, not after - #460

Open
cipoklean wants to merge 1 commit into
AssemblyAI:mainfrom
cipoklean:fix/applink-form-decode
Open

cipoklean wants to merge 1 commit into
AssemblyAI:mainfrom
cipoklean:fix/applink-form-decode

Conversation

@cipoklean

Copy link
Copy Markdown

What & why

Fixes #459.

AppLink.name(in:) read URLComponents.queryItems — already percent-decoded — and then swapped "+" for space. Form encoding defines "+" as a space before percent-decoding, so the swap order is backwards: a literal plus, correctly encoded as %2B by whoever wrote the link, decodes to "+" and is then corrupted to a space. A google search for c++ (q=c%2B%2B) extracted as "c ", and the mangled text is what preferApps matches installed app names against.

The fix reads percentEncodedQueryItems — the still-encoded items — applies the plus swap first, and percent-decodes after, which is the order the encoding defines. removingPercentEncoding returning nil on a malformed sequence is handled by the same guard as the rest.

How it was tested

The decode path is pure Foundation, so both orderings were verified byte-for-byte on Linux Swift 6.2.4 before committing:

query before after
q=c%2B%2B "c " "c++"
q=a+b "a b" "a b"
q=a%20b "a b" "a b"
q=%2B " " "+"

Regression test added to AppLinkTests pinning q=c%2B%2B → "c++". The existing suite's cases are encoding-neutral (q=how+to+open+threads+in+slack still exceeds the word gate). scripts/check.sh --portable green end-to-end; swift-format lint --strict clean on both files. CI on macos-26 is the authority on the Swift build and test run.

  • scripts/check.sh passes (or CI will, if I'm not on a Mac)
  • I read AGENTS.md and this doesn't reintroduce anything deliberately removed
  • Docs updated if behavior changed

AppLink read the decoded queryItems and then swapped + for space, which
cannot tell a form space from a literal plus: a search for c++ arrives
as q=c%2B%2B, decodes to c++, and the swap corrupted it to c-followed-
by-spaces. Reading percentEncodedQueryItems instead restores the order
the encoding defines: plus to space first, percent-decoding after.

Closes AssemblyAI#459

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AppLink decodes google search queries in the wrong order — a literal plus (%2B) is corrupted to a space

1 participant