docs(ios): fix Swift network-privacy regex leaving leading & in place - #48
Conversation
The Swift sample's regex was "&access_token=[0-9a-z\-]*" — an extra leading & that requires a preceding query parameter to match. When access_token is the first parameter in the URL (e.g. ?access_token=SECRET), the Swift version silently leaves it in the recorded network event, while the equivalent Objective-C sample (without the leading &) correctly strips it either way. This is sample code for a privacy/PII-redaction feature, so the bug directly undermines what the page is teaching. Dropped the leading & to match the Objective-C sample. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The sample force-unwrapped event.url to build the NSRange on the line *above* the `if (event.url != nil)` guard, so the guard never protected anything — a nil URL crashes the delegate. Rewrite as `if let url = event.url`, which covers both uses, and size the NSRange with url.utf16.count rather than url.count: NSRange indexes UTF-16 code units (matching the Objective-C sample's -length), so a URL with non-ASCII characters was under-covered and could skip matches. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Change-Id: I81be03aad11d0e3c370ebf1cf0f976f250338c93
|
Confirmed, and it's a real leak rather than a cosmetic mismatch. In I pushed one follow-up commit (a57a06c) for a second bug in the same block: let range = NSMakeRange(0 , (event.url!.count))
if (event.url != nil) {The force-unwrap is on the line above the nil guard, so the guard never protected anything — a nil URL crashes the delegate. Rewrote as While there I also switched the range to cspell clean (288 files, 0 issues). LGTM. 🤖 Generated with Claude Code |
krassx
left a comment
There was a problem hiding this comment.
Validated against source (see review comment above). Approving.
Summary
docs/sdk/ios/privacy/network.mdx: the Objective-C sample's redaction regex isaccess_token=[0-9a-z\-]*; the Swift sample's is&access_token=[0-9a-z\-]*— an extra leading&that requires a preceding query parameter to match.access_tokenis the first parameter in the URL (e.g.?access_token=SECRET), the Swift version silently leaves it in the recorded network event.Changes
&from the Swift regex so it matches the Objective-C sample's (correct) behavior.Test plan
npx cspellon the changed file — 0 issues🤖 Generated with Claude Code
https://claude.ai/code/session_01QnXDhVitCVmMNafPRvKUat