Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13908] Multiline strings with escaped quotes inside will ignore the escaping #56306

Closed
swift-ci opened this issue Nov 28, 2020 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13908
Radar rdar://problem/71912846
Original Reporter chiellienl (JIRA User)
Type Bug
Status Closed
Resolution Invalid
Environment

Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
Target: x86_64-apple-darwin20.1.0

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 1f06cbb94df72cf69c7323173919e262

Issue Description:

Assume I want to define a hardcoded JSON object:

let json = """
{
  "text": "This is text with \"quotes\" in it..."
}
"""

both the regular `"` as the `"` are interpreted the same.
json will be:

"{\n  \"text\": \"This is text with \"quotes\" in it...\"\n}"

which will invalidate my json object.

The expected interpretation would be:

"{\n \"text\": \"This is text with \\\"quotes\\\" in it...\"\n}"
@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Collaborator Author

swift-ci commented Dec 7, 2020

Comment by Kyle Macomber (JIRA)

This appears to behave to spec. From the SE-0168 decision rationale:

It should be clarified that multiline strings support the same escapes and interpolations as single-line strings. This allows a literal """ to be written """.

Note that you can use SE-0200 Raw Strings to instead of all the backslashes:

let json = #"""
{
  "text": "This is text with \"quotes\" in it..."
}
"""#

Or:

let json = #"{ "text": "This is text with \"quotes\" in it..." }"#

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants