Skip to content

emitter: emit quotes for non-plain scalars #1363

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

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

Conversation

johncoomes
Copy link

Use the "!" tag to detect scalars that are not plain scalars and pass EMITTER_MANIP::DoubleQuoted to Emitter::Write() to ensure they are quoted.

This preserves quotes on quoted items that do not strictly need quotes. The alternative of detecting and quoting only the values that need quotes seemed error-prone and brittle.

Fixes #1362.

Use the "!" tag to detect scalars that are not plain scalars and pass
EMITTER_MANIP::DoubleQuoted to Emitter::Write() to ensure they are quoted.

This preserves quotes on quoted items that do not strictly need quotes. The
alternative of detecting and quoting only the values that need quotes seemed
error-prone and brittle.

Fixes jbeder#1362.
out << n;
ExpectEmit("test");
ExpectEmit(quoted);
Copy link
Owner

Choose a reason for hiding this comment

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

This one is a little weird; I'd much prefer that it would display

test

rather than

"test"

since the quotes are redundant.

Copy link
Author

Choose a reason for hiding this comment

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

The behavior is different, but seems reasonable (to me) since the input value was already quoted; it's not adding quotes. To maintain correct behavior while only quoting when strictly necessary requires a reliable way to detect that it's safe to omit quotes. #1276 mentions using "a laundry list of regexes, such as those for all the number formats, infinities, true/false etc." to check. Looking at the yaml spec, that seems error prone.

Copy link
Author

Choose a reason for hiding this comment

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

Looking further in the yaml spec, it has a list of regular expressions in the Core Schema chapter. The regexes would be different for the fail-safe or json schemas, but AFAICT yaml-cpp does not support those.

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.

emitter loses type info for some strings
2 participants