-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[Parser] Detect non-breaking space (U+00A0) and offer a fix-it #16090
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1603ec2
[Parser] Detect nonbreaking space U+00A0 and fixit
hashemi e8c17b6
Move non-breaking space handling to lexUnknown
hashemi 9d28cd5
Add more non-breaking space test cases
hashemi 036b2f5
Minor style edits
hashemi 3c841b8
Add tests for non-breaking space detect and fix-it
hashemi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: %target-typecheck-verify-swift | ||
|
||
let nonBreakingSpace1 = 3 // expected-warning {{non-breaking space (U+00A0) used instead of regular space}} {{22-24= }} | ||
|
||
let nonBreakingSpace2 = 3 // expected-warning {{non-breaking space (U+00A0) used instead of regular space}} {{24-26= }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// RUN: cat %s | sed -e 's/'$(echo -ne "\x5a")'/'$(echo -ne "\xc2\xa0")'/g' > %t.tmp | ||
// RUN: cp -f %t.tmp %t | ||
// RUN: %swift-syntax-test -input-source-filename %t -dump-full-tokens 2>&1 | %FileCheck %t | ||
let a =Z3Z // nbsp(Z) | ||
let bZ= 3Z | ||
let cZ=Z3 | ||
|
||
// CHECK: 4:8: warning: non-breaking space (U+00A0) used instead of regular space | ||
// CHECK: 4:11: warning: non-breaking space (U+00A0) used instead of regular space | ||
// CHECK: 5:6: warning: non-breaking space (U+00A0) used instead of regular space | ||
// CHECK: 5:11: warning: non-breaking space (U+00A0) used instead of regular space | ||
// CHECK: 6:6: warning: non-breaking space (U+00A0) used instead of regular space | ||
// CHECK: 6:9: warning: non-breaking space (U+00A0) used instead of regular space | ||
|
||
// CHECK-LABEL: 4:7 | ||
// CHECK-NEXT:(Token equal | ||
// CHECK-NEXT: (text="=") | ||
// CHECK-NEXT: (trivia garbageText \302\240)) | ||
|
||
// CHECK-LABEL: 4:10 | ||
// CHECK-NEXT:(Token integer_literal | ||
// CHECK-NEXT: (text="3") | ||
// CHECK-NEXT: (trivia garbageText \302\240) | ||
// CHECK-NEXT: (trivia space 1)) | ||
|
||
// CHECK-LABEL: 5:5 | ||
// CHECK-NEXT:(Token identifier | ||
// CHECK-NEXT: (text="b") | ||
// CHECK-NEXT: (trivia garbageText \302\240)) | ||
|
||
// CHECK-LABEL: 5:10 | ||
// CHECK-NEXT:(Token integer_literal | ||
// CHECK-NEXT: (text="3") | ||
// CHECK-NEXT: (trivia garbageText \302\240) | ||
|
||
// CHECK-LABEL: 6:5 | ||
// CHECK-NEXT:(Token identifier | ||
// CHECK-NEXT: (text="c") | ||
// CHECK-NEXT: (trivia garbageText \302\240)) | ||
|
||
// CHECK-LABEL: 6:8 | ||
// CHECK-NEXT:(Token equal | ||
// CHECK-NEXT: (text="=") | ||
// CHECK-NEXT: (trivia garbageText \302\240)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm that this dereference is safe? Can we assume that the buffer is always null-terminated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's guaranteed. https://github.com/apple/swift/blob/9ba05efb/lib/Parse/Lexer.cpp#L188