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 regex pattern when caret and dollar sign exists in the pattern #22

Closed
wants to merge 1 commit into from

Conversation

jemershaw
Copy link

No description provided.

@jemershaw
Copy link
Author

@llhotka -- Do you mind reviewing this PR?

@llhotka
Copy link
Member

llhotka commented Jun 11, 2019

This is not correct. YANG uses the XSD flavour of regular expressions in which the characters ^ and $ keep their literal meaning. So, for example,

pattern '$';

matches the string $.

Correction: The ^ character is in fact special in XSD regex patterns and must be escaped to have the literal meaning. This doesn't change the argument though.

@llhotka llhotka closed this Jun 11, 2019
@jemershaw
Copy link
Author

@llhotka I understand ^ and $ are their literal meaning. Please see https://github.com/openconfig/public/blob/master/release/models/types/openconfig-inet-types.yang#L81 which this is currently trying to solve since we don't want to include the ^ and $ meaning in the pattern.

@llhotka
Copy link
Member

llhotka commented Jun 12, 2019

Yangson is based on IETF standards, OpenConfig folks often don't care too much about them. In this case, I believe they use another flavour of regular expressions, so there may possibly be other differences apart from the ^ and $ characters. So I suggest that you open an issue in the openconfig project.

@dbarrosop
Copy link

dbarrosop commented Jun 12, 2019

@llhotka Would you consider a PR that let's yangson choose between XSD style regexes (the default) and posix? Something like:

dm = DataModel.from_file('yang-library-ex2.json', [".", "../../../yang-modules/ietf"], regex_style={datamodel.PosixRegex, datamodel.XSDRegex})

Defaulting to XSDRegex, of course, to avoid changing the current behavior unless told explicitly.

I understand it's all Openconfig's fault but not supporting the best known repository of yang models feels like a big loss. Also, PosixRegex is better understood and more widely used.

@llhotka
Copy link
Member

llhotka commented Jun 12, 2019

@dbarrosop This would make sense if the regex flavour is somehow declared in the YANG module, because otherwise it would be difficult to combine YANG modules using different flavours. I started a thread on this in the NETMOD mailing list.

@dbarrosop
Copy link

Yeah, I agree, ideally openconfig wouldn't break the standard... I am going to evaluate forking openconfig and fixing the regexes, if that turns out to be a reasonable alternative I will go that way, otherwise, I will show up here again to see if there is something we can do to fix this in the short-term. I am a huge fan of yangson and jetconf and wouldn't want to have to look for alternatives because of Openconfig... :(

Awesome work by the way, huge fan of yangson and jetconf as I said :)

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.

3 participants