sphinx-needs icon indicating copy to clipboard operation
sphinx-needs copied to clipboard

FIX: Use `re.fullmatch` for `needs_id_regex` in need creation

Open chrisjsewell opened this issue 1 year ago • 2 comments

The regex supplied should be assumed to match the entire string, rather than be a partial match (as is the case currently using re.match).

This is then consistent with the usage of needs_id_regex in:

  • https://github.com/useblocks/sphinx-needs/blob/1de1a7a047bfc7912ea0aa779ffb187def7a5254/sphinx_needs/directives/needextend.py#L111
    • https://github.com/useblocks/sphinx-needs/blob/1de1a7a047bfc7912ea0aa779ffb187def7a5254/sphinx_needs/directives/needextract.py#L103

chrisjsewell avatar Jul 01 '24 13:07 chrisjsewell

@danwos this now fails our docs build and some tests, because there it appears that regex is assumed to only be partial (only checking the start of the string).

So the question would be, do we instead change the code in needextend and needextract to use re.match, rather than re.fullmatch

chrisjsewell avatar Jul 01 '24 13:07 chrisjsewell

Good point, I guess the user can reach fullmatch by using in the configured regex an ending $ right? So yes, we should change it then also to match for needextend and co.

danwos avatar Jul 01 '24 13:07 danwos