Skip to content

Conversation

@jk53bg
Copy link

@jk53bg jk53bg 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

@jk53bg jk53bg changed the title #17 Fixed parsing for property values containing '=' Fix parsing for property values containing '=' Jun 18, 2020
@jk53bg jk53bg force-pushed the fix-parsing-#17 branch from 77e6bda to 6923813 Compare June 18, 2020 20:33
@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