Repository navigation
Detect base64 from the data URL header, not the payload - #309
Conversation
varun06
left a comment
There was a problem hiding this comment.
Thanks @akhilcb, the fix looks right to me. Capturing the ;base64 marker, which the regex already
limits to the header, is exactly what's needed, and the new test fails on main without the fix.
One request: could you drop the last commit (test: disable reconnection in the heartbeat failure test)?
- It's unrelated to data URLs.
- With reconnection disabled, nothing in the transport touches the connection after the simulated failure, so the test only checks the state the mock set itself.
- It also conflicts with #283: once that cancels the connection when reconnection is disabled, the state becomes
.cancelledand this test fails. I reproduced that locally.
If the test is flaky as written, a separate PR that asserts the transport's behavior would be great.
Minor: once #295 lands, Value no longer turns data URLs into .data, so the "Breaking Changes" note can be updated then.
86fb7bf to
2d1d8c4
Compare
Data.parseDataURL decided base64 with string.contains(";base64,"), which
also searched the payload, so "data:text/plain,hello;base64,world" was
treated as base64 and returned nil even though isDataURL accepted it.
The regex now captures the optional ;base64 marker and that capture
drives the decision.
2d1d8c4 to
34c8cfb
Compare
|
@varun06 Thanks for the review. I have dropped the heartbeat commit, so this PR now has only the two data URL commits. I also rebased it onto the latest main while I was at it. You are right that the reconnection change doesn't belong here and good catch on #283. With reconnection disabled, the test only checks the state the mock set itself, so it isn't testing anything in the transport. I'll take another look and open a separate PR that asserts the transport's behavior instead. I will update the Breaking Changes note once #295 lands. |
|
I have raised this PR based on our above discussion: #311. Thank you! |
Motivation and Context
Data.parseDataURLdecided whether a data URL is base64 withstring.contains(";base64,"), which searches the payload too, not just the header. Aplain-text data URL whose content contains
;base64,was treated as base64, failed todecode, and returned
nil:isDataURLreturnstruefor the same string, so the two functions disagreed.The data URL regex now captures the optional
;base64marker, and that capture decideswhether to decode base64. The payload is never searched.
How Has This Been Tested?
Adds tests for:
isDataURLandparseDataURLagree;;base64,data URLs still decode as base64;;base64following acharsetparameter (data:text/plain;charset=utf-8;base64,SGk=).swift testpasses.Breaking Changes
None.
Valuedecoding followsparseDataURL, so a JSON string like the one above nowdecodes as
.data, as other data-URL strings already do.Types of changes