unicode: remove variation selectors from IsGraphic and IsPrint
IsGraphic and IsPrint return true for Variation Selectors, which are invisible. This just adds a check to not include those, and a test to verify.
Fixes #73673
diff --git a/src/unicode/graphic.go b/src/unicode/graphic.go
index aa62f2a..f5c2773 100644
--- a/src/unicode/graphic.go
+++ b/src/unicode/graphic.go
@@ -39,6 +39,9 @@
if uint32(r) <= MaxLatin1 {
return properties[uint8(r)]&pg != 0
}
+ if Is(Variation_Selector, r) {
+ return false
+ }
return In(r, GraphicRanges...)
}
@@ -51,6 +54,9 @@
if uint32(r) <= MaxLatin1 {
return properties[uint8(r)]&pp != 0
}
+ if Is(Variation_Selector, r) {
+ return false
+ }
return In(r, PrintRanges...)
}
diff --git a/src/unicode/graphic_test.go b/src/unicode/graphic_test.go
index c9f289c..15167e6 100644
--- a/src/unicode/graphic_test.go
+++ b/src/unicode/graphic_test.go
@@ -101,6 +101,50 @@
}
}
+func TestIsGraphicVariationSelector(t *testing.T) {
+ // Variation selectors are invisible and should return false for IsGraphic.
+ for _, r16 := range Variation_Selector.R16 {
+ for r := rune(r16.Lo); r <= rune(r16.Hi); r += rune(r16.Stride) {
+ got := IsGraphic(r)
+ want := false
+ if got != want {
+ t.Errorf("%U incorrect: got %t; want %t", r, got, want)
+ }
+ }
+ }
+ for _, r32 := range Variation_Selector.R32 {
+ for r := rune(r32.Lo); r <= rune(r32.Hi); r += rune(r32.Stride) {
+ got := IsGraphic(r)
+ want := false
+ if got != want {
+ t.Errorf("%U incorrect: got %t; want %t", r, got, want)
+ }
+ }
+ }
+}
+
+func TestIsPrintVariationSelector(t *testing.T) {
+ // Variation selectors are invisible and should return false for IsPrint.
+ for _, r16 := range Variation_Selector.R16 {
+ for r := rune(r16.Lo); r <= rune(r16.Hi); r += rune(r16.Stride) {
+ got := IsPrint(r)
+ want := false
+ if got != want {
+ t.Errorf("%U incorrect: got %t; want %t", r, got, want)
+ }
+ }
+ }
+ for _, r32 := range Variation_Selector.R32 {
+ for r := rune(r32.Lo); r <= rune(r32.Hi); r += rune(r32.Stride) {
+ got := IsPrint(r)
+ want := false
+ if got != want {
+ t.Errorf("%U incorrect: got %t; want %t", r, got, want)
+ }
+ }
+ }
+}
+
func TestIsSpaceLatin1(t *testing.T) {
for i := rune(0); i <= MaxLatin1; i++ {
got := IsSpace(i)
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
I spotted some possible problems with your PR:
1. You have a long 146 character line in the commit message body. Please add line breaks to long lines that should be wrapped. Lines in the commit message body should be wrapped at ~76 characters unless needed for things like URLs or tables. (Note: GitHub might render long lines as soft-wrapped, so double-check in the Gerrit commit message shown above.)
2. Do you have the right bug reference format? For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message.
Please address any problems by updating the GitHub PR.
When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.
To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.
For more details, see:
(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Congratulations on opening your first change. Thank you for your contribution!
Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.
Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.
During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
I spotted some possible problems with your PR:
1. You have a long 146 character line in the commit message body. Please add line breaks to long lines that should be wrapped. Lines in the commit message body should be wrapped at ~76 characters unless needed for things like URLs or tables. (Note: GitHub might render long lines as soft-wrapped, so double-check in the Gerrit commit message shown above.)
2. Do you have the right bug reference format? For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message.Please address any problems by updating the GitHub PR.
When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.
To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.
For more details, see:
- [how to update commit messages](https://go.dev/wiki/GerritBot/#how-does-gerritbot-determine-the-final-commit-message) for PRs imported into Gerrit.
- the Go project's [conventions for commit messages](https://go.dev/doc/contribute#commit_messages) that you should follow.
(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)
Done
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
if Is(Variation_Selector, r) {Can't pg (and pp below) be tweaked to do this? That feels like the right way to solve this.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
if Is(Variation_Selector, r) {Can't pg (and pp below) be tweaked to do this? That feels like the right way to solve this.
It looks like pg is not entered for variation selectors because theyre out of the latin1 range. Is there a more elegant way to solve this you think other than this if check?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |