-
Notifications
You must be signed in to change notification settings - Fork 14.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
Add script for detecting bad characters. #27315
Conversation
Deploy preview for kubernetes-io-master-staging ready! Built with commit 7fde042 https://deploy-preview-27315--kubernetes-io-master-staging.netlify.app |
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.
Nice idea
We could run this as a CI test, in fact.
Could you add how to use this script to the README? |
@sftim That is a nice idea. /cc @oomichi |
b85da54
to
6d728ec
Compare
@s-ito-ts
|
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.
some comments to make the code more readable.
scripts/check-ctrlcode.py
Outdated
|
||
def check_dir(path, ext): | ||
for f in os.listdir(path): | ||
if(f[0] != "."): |
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.
To reduce nests, here can be
if(f[0] == "."):
continue
fullpath = os.path.join(path, f)
...
scripts/check-ctrlcode.py
Outdated
fullpath = os.path.join(path, f) | ||
if(os.path.isfile(fullpath)): | ||
exts = os.path.splitext(f) | ||
if(exts[1] == ext): |
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.
ditto:
if(exts[1] != ext):
continue
check_ctrlcode(fullpath)
scripts/check-ctrlcode.py
Outdated
with open(filepath, encoding='utf-8') as f: | ||
while True: | ||
str = f.readline() | ||
if str: |
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.
ditto:
if str == "":
break
line = line + 1
# check 0x00-0x1f except 0x09(HT), 0x0a(LF), 0x0d(CR)
...
scripts/check-ctrlcode.py
Outdated
# check 0x00-0x1f except 0x09(HT), 0x0a(LF), 0x0d(CR) | ||
pattern = re.compile('[\u0000-\u0008\u000b\u000c\u000e-\u001f]') | ||
m = pattern.search(str) | ||
if(m != None): |
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.
ditto:
if(m == None):
continue
pos = m.end()
ctrl = m.group().encode("utf-8")
...
6d728ec
to
fc68dcb
Compare
@oomichi |
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.
Thanks for updating.
Most part seems good for me, just one comment.
continue | ||
check_ctrlcode(fullpath) | ||
else: | ||
check_dir(fullpath, ext) |
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.
similar point. How about changing line 30-34 to
if(os.path.isdir(fullpath)):
check_dir(fullpath, ext)
continue
exts = os.path.splitext(f)
if(exts[1] != ext):
continue
check_ctrlcode(fullpath)
?
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.
I don't think nest is a problem.
I thought about the ease of understanding the conditions.
My code feels easy to understand the if-else condition.
Your code feels easy to understand as a loop condition.
I would like to accept your proposal and fix it.
After fixed, I'll request you to review.
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.
This point is not only for nest.
This point makes condition same as the next called function.
In my suggestion, isdir()
condition calls check_dir()
.
I think that is pretty straightforward and easy to understand what is the purpose here.
Co-authored-by: Shu Muto <shu.mutow@nec.com>
fc68dcb
to
7fde042
Compare
@oomichi |
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.
Thanks for updating.
/lgtm
LGTM label has been added. Git tree hash: 73d9393f4624ed62b81eb568c45ad201cf84c7a2
|
/assign @steveperry-53 Could you please review? |
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.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: savitharaghunathan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This is script that find control-code(0x00-0x1f) in text files.
I could find them in several files. Please look at PR #26965, #27173, #27171.