-
Notifications
You must be signed in to change notification settings - Fork 8
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 parsing for property values containing '=' #18
base: master
Are you sure you want to change the base?
Conversation
77e6bda
to
6923813
Compare
Hey @johlandabee, thanks for sending this over! |
extendedconfigfile = "generic-ubuntu1804-vmware.vmxf" | ||
floppy0.present = "FALSE" | ||
guestos = "ubuntu-64" | ||
guestos.detailed.data = "bitness='64' distroName='Ubuntu' distroVersion='18.04' familyName='Linux' kernelVersion='4.15.0-76-generic' prettyName='Ubuntu 18.04.4 LTS'" |
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.
It seems a splitN
would do it, no need for the regular expression unless I'm missing something here.
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.
here is an example: https://play.golang.org/p/tCDvzaz_Hjg
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.
Yeah, that should do it. Didn't think of SplitN. Nice thing about the regular expression is you don't need to check for comments, empty values or unquote separately. That is assuming there are never values without quotes.
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.
They are also harder to maintain, more inefficient and often come with unexpected side effects.
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.
Well it might not be as efficient, but less code also leaves less margin for error. I don't necessarily agree on the maintainability or side effect aspect, but I can change the PR if you want.
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.
Well it might not be as efficient, but less code also leaves less margin for error
Agreed, it is another reason why I prefer using strings.SplitN()
, it solves the problem with the least amount of code involved.
Parse key value pairs using named regex groups. This should be overall more error tolerant.
Regex explained at https://regex101.com/r/8ImGSW/1
Fixes #17