Skip to content

Commit 90ec53b

Browse files
committed
cstyle: Allow URLs in C++ comments
If a C++ comment contained a URL, the `://` part of the URL would trigger an error because there was no trailing blank, but trailing blanks make for an invalid URL. Modify the check to ignore text within the C++ comment. Signed-off-by: Chris Lindee <chris.lindee+github@gmail.com> Closes: #13987
1 parent 48cf170 commit 90ec53b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

scripts/cstyle.pl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,6 @@ ($$)
498498
if (/\S\*\/[^)]|\S\*\/$/ && !/$lint_re/) {
499499
err("missing blank before close comment");
500500
}
501-
if (/\/\/\S/) { # C++ comments
502-
err("missing blank after start comment");
503-
}
504501
# check for unterminated single line comments, but allow them when
505502
# they are used to comment out the argument list of a function
506503
# declaration.
@@ -534,7 +531,15 @@ ($$)
534531
# multiple comments on the same line.
535532
#
536533
s/\/\*.*?\*\///g;
537-
s/\/\/.*$//; # C++ comments
534+
s/\/\/(?:\s.*)?$//; # Valid C++ comments
535+
536+
# After stripping correctly spaced comments, check for (and strip) comments
537+
# without a blank. By checking this after clearing out C++ comments that
538+
# correctly have a blank, we guarantee URIs in a C++ comment will not cause
539+
# an error.
540+
if (s!//.*$!!) { # C++ comments
541+
err("missing blank after start comment");
542+
}
538543

539544
# delete any trailing whitespace; we have already checked for that.
540545
s/\s*$//;

0 commit comments

Comments
 (0)