Re: Json
Re: Json
- Subject: Re: Json
- From: has <email@hidden>
- Date: Wed, 18 Feb 2015 18:26:02 +0000
Shane Stanley wrote:
>
>> > set someString to someString's
stringByReplacingOccurrencesOfString:"\\/" withString:"/"
>>
>> Don't do that, it\\\/s unsafe.
>
> I understand why it should be unnecessary, but I fear I'm missing
something in your cryptic "it\\\/s". Care to expand on why it's unsafe?
Yes-no-sorry-that's sleep dep talking. I'm thinking of the general case,
where a plain text find-and-replace for \/ sequences will not only match
an escaped slash (A\/B -> A/B) but _also_ an escaped backslash followed
by an slash (A\\/B -> A\/B). To prevent the latter mismatch, you need to
check bounds as well, e.g. by using a regular expression (?:^|[^\\])\\/.
But of course NSJSONSerialization always_ escapes slashes, so the A\\/B
sequence will _never_ appear in its output; it'll always be A\\\/B (i.e.
escaped backslash followed by escaped slash). So you're safe in that
special case. OTOH, if it ain't broken, don't fix it: you don't need to
consider what nasty corner cases might sneak in if you don't mess with
it in the first place. Which is nice, especially when N+1 levels of
backslash-escaping is involved.
Cheers,
has
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden