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 parsing for property values containing '=' #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

johlandabee
Copy link

@johlandabee johlandabee commented Jun 18, 2020

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

@johlandabee johlandabee changed the title #17 Fixed parsing for property values containing '=' Fix parsing for property values containing '=' Jun 18, 2020
@c4milo
Copy link
Member

c4milo commented Jun 25, 2020

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'"
Copy link
Member

@c4milo c4milo Jun 25, 2020

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.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

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.

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.

VMX property values that can contain '=' characters break parsing
2 participants