Skip to content

Fix regex to cover '1 commit result' case #78

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

Merged
merged 1 commit into from
Feb 7, 2021

Conversation

Yikun
Copy link
Contributor

@Yikun Yikun commented Feb 5, 2021

Current regex doesn't cover '1 commit result' case, that means if we
get only 1 commit result, the dependent number will be set to 0.

This patch try to fix it by use '* commit result' to match 'n commit results'
and '1 commit result' case.

Current regex doesn't cover '1 commit result' case, that means if we
get only 1 commit result, the dependent number will be set to 0.

This patch try to fix it by use '* commit result' to match 'n commit results'
and '1 commit result' case.
@Yikun
Copy link
Contributor Author

Yikun commented Feb 7, 2021

Notes for reviewer:

regex_old=b'.*[^0-9,]([0-9,]+).*commit results'
regex_new=b'.*[^0-9,]([0-9,]+).*commit result'

# the old regex can't match 1 commit result
>>> re.compile(regex_old).match(b'<p>100 commit results</p>').group(1)
b'100'
>>> re.compile(regex_old).match(b'<p>1 commit result</p>').group(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'

# the new regext can match 1 commit result and n commit results
>>> re.compile(regex_new).match(b'<p>100 commit results</p>').group(1)
b'100'
>>> re.compile(regex_new).match(b'<p>1 commit result</p>').group(1)
b'1'

case snapshot:
image

[1] https://github.com/search?q=kunpengcompute%2Fkunpeng&type=commits

@inferno-chromium inferno-chromium merged commit 5b741f0 into ossf:main Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants