Skip to contentSkip to conversation

checkpatch: use utf-8 match for spell checking

PATCH Superseded Antonio Borneo 3 participants 6 messages Dec 12, 2023 – May 20, 2025 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: use utf-8 match for spell checking

The current code that checks for misspelling verifies, in a more complex regex, if $rawline matches [^\w]($misspellings)[^\w]

Being $rawline a byte-string, a utf-8 character in $rawline can match the non-word-char [^\w].
E.g.:

	./script/checkpatch.pl --git 81c2f059ab9
	WARNING: 'ment' may be misspelled - perhaps 'meant'?
	#36: FILE: MAINTAINERS:14360:
	+M:     Clément Léger <[email protected]>
	            ^^^^

Use a utf-8 version of $rawline for spell checking.

---
 scripts/checkpatch.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
index 25fdb7fda112..58646bd6ef56 100755
@@ -3477,7 +3477,8 @@ sub process {
 # Check for various typo / spelling mistakes
 		if (defined($misspellings) &&
 		    ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
-			while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
+			my $rawline_utf8 = decode("utf8", $rawline);
+			while ($rawline_utf8 =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
 				my $typo = $1;
 				my $blank = copy_spacing($rawline);
 				my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);

base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86

Signature · 1 line
2.42.0
maintainer
#1 lore raw
Quoted 12 lines · Antonio Borneo

The current code that checks for misspelling verifies, in a more complex regex, if $rawline matches [^\w]($misspellings)[^\w]

Being $rawline a byte-string, a utf-8 character in $rawline can match the non-word-char [^\w].
E.g.:

	./script/checkpatch.pl --git 81c2f059ab9
	WARNING: 'ment' may be misspelled - perhaps 'meant'?
	#36: FILE: MAINTAINERS:14360:
	+M:     Clément Léger <[email protected]>
	            ^^^^
Quoted 4 lines

Use a utf-8 version of $rawline for spell checking.

Seems sensible, thanks, but:

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

scripts/checkpatch.pl sub process { · line 3483

Quoted 9 lines
scripts/checkpatch.pl +2 -1
@@ -3477,7 +3477,8 @@ sub process {
 # Check for various typo / spelling mistakes
 		if (defined($misspellings) &&
 		    ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
-			while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
+			my $rawline_utf8 = decode("utf8", $rawline);
+			while ($rawline_utf8 =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
 				my $typo = $1;
 				my $blank = copy_spacing($rawline);

Maybe this needs to use $rawline_utf8 ?

scripts/checkpatch.pl sub process { · line 3484

Quoted 1 line
scripts/checkpatch.pl +0 -0
 				my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);

And may now the $fix bit will not always work properly

#2 lore raw
Quoted 22 lines · Joe Perches
Quoted 12 lines · Antonio Borneo

The current code that checks for misspelling verifies, in a more complex regex, if $rawline matches [^\w]($misspellings)[^\w]

Being $rawline a byte-string, a utf-8 character in $rawline can match the non-word-char [^\w].
E.g.:
        ./script/checkpatch.pl --git 81c2f059ab9
        WARNING: 'ment' may be misspelled - perhaps 'meant'? #36: FILE: MAINTAINERS:14360:
        +M:     Clément Léger <[email protected]> ^^^^

Quoted 4 lines

Use a utf-8 version of $rawline for spell checking.

Seems sensible, thanks, but:

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

Quoted 11 lines
Quoted 9 lines
scripts/checkpatch.pl +0 -0
@@ -3477,7 +3477,8 @@ sub process {
  # Check for various typo / spelling mistakes

                if (defined($misspellings) &&
                    ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
-                       while ($rawline =~ /(?:^|[^\w\-'])($misspellings)(?:[^\w\-']|$)/gi) { +                       my $rawline_utf8 = decode("utf8", $rawline);
+                       while ($rawline_utf8 =~ /(?:^|[^\w\-'])($misspellings)(?:[^\w\-']|$)/gi) { my $typo = $1;
                                my $blank = copy_spacing($rawline);

Maybe this needs to use $rawline_utf8 ?

Correct, I will send a v2!

Quoted 4 lines
Quoted 2 lines

                                my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);

And may now the $fix bit will not always work properly

I have run some test and it looks ok with current ASCII file scripts/spelling.txt.

I have also tested adding some utf-8 string in the spelling file, but checkpatch reads it as ASCII and extending it to utf-8 will require further modifications in checkpatch, way beyond this simple fix.

Thanks for the review.
Antonio

#3 lore raw

PATCH v2 1/1 checkpatch: use utf-8 match for spell checking

In reply to Antonio Borneo

The current code that checks for misspelling verifies, in a more complex regex, if $rawline matches [^\w]($misspellings)[^\w]

Being $rawline a byte-string, a utf-8 character in $rawline can match the non-word-char [^\w].
E.g.:

	./scripts/checkpatch.pl --git 81c2f059ab9
	WARNING: 'ment' may be misspelled - perhaps 'meant'?
	#36: FILE: MAINTAINERS:14360:
	+M:     Clément Léger <[email protected]>
	            ^^^^

Use a utf-8 version of $rawline for spell checking.

---
Changes in v2:
- use $rawline_utf8 also in the while-loop's body;
- fix path of checkpatch in the commit message.

---
 scripts/checkpatch.pl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +3 -2
index 25fdb7fda112..2d122d232c6d 100755
@@ -3477,9 +3477,10 @@ sub process {
 # Check for various typo / spelling mistakes
 		if (defined($misspellings) &&
 		    ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
-			while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
+			my $rawline_utf8 = decode("utf8", $rawline);
+			while ($rawline_utf8 =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
 				my $typo = $1;
-				my $blank = copy_spacing($rawline);
+				my $blank = copy_spacing($rawline_utf8);
 				my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);
 				my $hereptr = "$hereline$ptr\n";
 				my $typo_fix = $spelling_fix{lc($typo)};

base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86

Signature · 1 line
2.42.0
#4 lore raw

Hello,

A gentle reminder to review this patch.

Best regards,

Clément

Quoted 43 lines · Antonio Borneo

The current code that checks for misspelling verifies, in a more complex regex, if $rawline matches [^\w]($misspellings)[^\w]

Being $rawline a byte-string, a utf-8 character in $rawline can match the non-word-char [^\w].
E.g.:

	./scripts/checkpatch.pl --git 81c2f059ab9
	WARNING: 'ment' may be misspelled - perhaps 'meant'?
	#36: FILE: MAINTAINERS:14360:
	+M:     Clément Léger <[email protected]>
	            ^^^^

Use a utf-8 version of $rawline for spell checking.

---
Changes in v2:
- use $rawline_utf8 also in the while-loop's body;
- fix path of checkpatch in the commit message.

---
  scripts/checkpatch.pl | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +3 -2
index 25fdb7fda112..2d122d232c6d 100755
@@ -3477,9 +3477,10 @@ sub process {
  # Check for various typo / spelling mistakes
  		if (defined($misspellings) &&
  		    ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
-			while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
+			my $rawline_utf8 = decode("utf8", $rawline);
+			while ($rawline_utf8 =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
  				my $typo = $1;
-				my $blank = copy_spacing($rawline);
+				my $blank = copy_spacing($rawline_utf8);
  				my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);
  				my $hereptr = "$hereline$ptr\n";
  				my $typo_fix = $spelling_fix{lc($typo)};

base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86

#5 lore raw
Quoted 53 lines · Clement LE GOFFIC

Hello,

A gentle reminder to review this patch.

Best regards,

Clément

Quoted 44 lines · Antonio Borneo

The current code that checks for misspelling verifies, in a more complex regex, if $rawline matches [^\w]($misspellings)[^\w]

Being $rawline a byte-string, a utf-8 character in $rawline can match the non-word-char [^\w].
E.g.:
    ./scripts/checkpatch.pl --git 81c2f059ab9
    WARNING: 'ment' may be misspelled - perhaps 'meant'? #36: FILE: MAINTAINERS:14360:
    +M:     Clément Léger <[email protected]> ^^^^

Use a utf-8 version of $rawline for spell checking.

---
Changes in v2:
- use $rawline_utf8 also in the while-loop's body;
- fix path of checkpatch in the commit message.
---
  scripts/checkpatch.pl | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +0 -0
index 25fdb7fda112..2d122d232c6d 100755
@@ -3477,9 +3477,10 @@ sub process {
   # Check for various typo / spelling mistakes

          if (defined($misspellings) &&
              ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) { -            while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:
[^\w\-'`]|$)/gi) {
+            my $rawline_utf8 = decode("utf8", $rawline);
+            while ($rawline_utf8 =~ /(?:^|[^\w\-'])($misspellings) (?:[^\w\-']|$)/gi) {
                  my $typo = $1;
-                my $blank = copy_spacing($rawline);
+                my $blank = copy_spacing($rawline_utf8);
                  my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo); my $hereptr = "$hereline$ptr\n";
                  my $typo_fix = $spelling_fix{lc($typo)};

Quoted 1 line
Quoted 1 line

base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86

Hi,

Is it just due to -ENOTIME for the maintainers, or are there doubts about this patch? (inspired from a response of Uwe).

Clément