Skip to content
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

Fix square bracket checking to account for arbitrary nested parentheses #81

Merged
merged 3 commits into from
Sep 23, 2020

Conversation

chisholm
Copy link
Contributor

Fixes #80 .

The leading_characters() approach doesn't work, since it was designed to get a specific number of non-whitespace characters. The number of characters necessary to check is unpredictable, so I've redesigned that whole approach. I renamed the function, and now it doesn't return leading characters since it seemed unnecessary. Instead, it does the check itself and returns True/False. The old start variable and parameter to the STIX version-specific run_validator() functions is removed. I didn't see any need for the latter functions to add the specialized error message when the caller could do it just as easily.

There were also some minor edits to unrelated files due to pre-commit.

@codecov-commenter
Copy link

codecov-commenter commented Sep 15, 2020

Codecov Report

Merging #81 into master will increase coverage by 0.06%.
The diff coverage is 96.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #81      +/-   ##
==========================================
+ Coverage   82.07%   82.13%   +0.06%     
==========================================
  Files          31       31              
  Lines        4865     4876      +11     
==========================================
+ Hits         3993     4005      +12     
+ Misses        872      871       -1     
Impacted Files Coverage Δ
stix2patterns/v20/object_validator.py 100.00% <ø> (ø)
stix2patterns/v21/object_validator.py 100.00% <ø> (ø)
stix2patterns/validator.py 50.00% <87.50%> (+0.84%) ⬆️
stix2patterns/helpers.py 100.00% <100.00%> (ø)
stix2patterns/test/test_helpers.py 100.00% <100.00%> (ø)
stix2patterns/v20/validator.py 100.00% <100.00%> (ø)
stix2patterns/v21/validator.py 100.00% <100.00%> (ø)
stix2patterns/test/v20/test_inspector.py 100.00% <0.00%> (ø)
stix2patterns/test/v20/test_validator.py 100.00% <0.00%> (ø)
stix2patterns/test/v21/test_inspector.py 100.00% <0.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2dafa44...6c283b7. Read the comment docs.

brackets checking.  I had simply carried over what was there
before, but it really seemed insufficient...
stripped.append(char)
# There can be an arbitrary number of open parens first... skip over those
c = next(non_ws_chars, None)
while c == "(":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be simpler to treat open parens and whitespace chars equally? Can we just check while c == "(" or c.isspace(): here instead of creating non_ws_chars?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... that would work too. If anything more complex were happening, it might make more sense to separate the whitespace skipping from the other processing, but it does seem kinda silly here since it's so simple. I'll change it.

Copy link
Contributor

@clenk clenk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @chisholm!

@clenk clenk merged commit 9186d3f into oasis-open:master Sep 23, 2020
@chisholm chisholm deleted the fix_brackets_check branch September 23, 2020 22:10
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.

Brackets check doesn't account for arbitrary nested parentheses
3 participants