-
Notifications
You must be signed in to change notification settings - Fork 321
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
Allow colons in plain scalars inside flow collections #104
Conversation
baeec9e
to
a9606b7
Compare
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.
I see no reason to refuse [:foo]
. It is valid YAML 1.1 meaning [ ":foo" ]
. My proposed change would make it to be successfully parsed. It would also cause [foo:]
to be parsed as [ "foo:]"
(because that's what the spec defines). It could be valid if another ]
follows.
|| CHECK_AT(parser->buffer, '{', 1) | ||
|| CHECK_AT(parser->buffer, '}', 1) | ||
) | ||
) { |
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.
This change is undesirable. Regardless of how strange it is, [foo:]]
is valid YAML 1.1 meaning [ "foo:]" ]
. Moreover, ?
certainly is not a flow indicator, so I am unsure how it found its way in here.
I think the correct fix would be to remove this if
statement altogether (frankly, I have no idea why it is there in the first place; x:x
is completely valid in a plain scalar inside flow content). :
with succeeding space is handled later on. Note the comment about example 8.13 in the spec. That example is wrong! It shows this YAML:
{
? foo :°,
?° : bar,
}
°
meaning empty scalar. This is not valid according to the productions, because there must be space after the :
before the ,
.
However, if I understand the rest of the code correctly, removing the if statement would cause [foo:]
be parsed as [ "foo:" ]
because the code is not designed to eat the character after the :
as it should according to the spec. My proposed solution would be having a local ate_colon
and then instead of the if:
ate_colon = CHECK(parser->buffer, ':');
and then at the end of the loop:
/* Copy the character. */
if (!READ(parser, string)) goto error;
if (ate_colon) if (!READ(parser, string)) goto error; /* <<< add this line */
end_mark = parser->mark;
if (!CACHE(parser, 2)) goto error;
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.
Moreover, ? certainly is not a flow indicator, so I am unsure how it found its way in here.
I added this for consistency, because it's also in the next if-statement. Maybe I should take it out in both statements. Then [foo:?bar]
would be allowed.
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.
This change is undesirable. Regardless of how strange it is,
[foo:]]
is valid YAML 1.1
The point is that this currently is not allowed in libyaml, and I just keep it like that with this change. The only thing which changes is to allow [foo:bar]
.
ns-plain-char - ,[]{}
characters after the colon. So I don't know why this change would be undesirable.
Could you clarify what you mean?
The goal of this PR is to accept things that make sense and are valid, but leaving the other cases alone for now, as I wrote above.
The problem is, if I allow that, then other cases break. If I change the code to allow The code can probably be fixed allowing |
I agree that the 1.1 spec production says that, but the sentence before production 154 says something different. http://yaml.org/spec/1.1/#id907281 |
@flyx I removed the However, this is a change on its own, allowing Edit: I reverted this change |
1fcc5e0
to
a9606b7
Compare
@perlpunk : what is https://github.com/yaml/yaml-test-suite ? |
@asomov It's a collection of test cases for YAML 1.2. You take the Edit: Actually, you should get the data from the releases: https://github.com/yaml/yaml-test-suite/releases |
@perlpunk cool ! But I do not understand how you run the test suite against SnakeYAML. |
@asomov for generating http://matrix.yaml.io/ we are using the programs in https://github.com/yaml/yaml-editor. Here are the ones for SnakeYAML: https://github.com/yaml/yaml-editor/tree/master/docker/src/java/src/main/java/org/yaml/editor (Getting a bit off topic here, for specific questions maybe create an issue or join #yaml on freenode) |
I compared several cases with various parsers and libyaml master and this PR applied: |
This is a followup to yaml#28 See http://yaml.org/spec/1.1/#nb-plain-char(c) and the following productions. This commit will allow `[http://example]`, but still fail for: - `[:foo]` - `[foo:]`
Rebased to current master and squashed the two commits |
Applied. Pushed. Thanks! |
Changes ======= * yaml/libyaml#95 -- build: do not install config.h * yaml/libyaml#97 -- appveyor.yml: fix Release build * yaml/libyaml#103 -- Remove unused code in yaml_document_delete * yaml/libyaml#104 -- Allow colons in plain scalars inside flow collections * yaml/libyaml#109 -- Fix comparison in tests/run-emitter.c * yaml/libyaml#117 -- Fix typo error * yaml/libyaml#119 -- The closing single quote needs to be indented... * yaml/libyaml#121 -- fix token name typos in comments * yaml/libyaml#122 -- Revert removing of open_ended after top level plain scalar * yaml/libyaml#125 -- Cherry-picks from PR 27 * yaml/libyaml#135 -- Windows/C89 compatibility * yaml/libyaml#136 -- allow override of Windows static lib name
Fix portlint errors in Makefile Changes in 0.2.2: * yaml/libyaml#95 -- build: do not install config.h * yaml/libyaml#97 -- appveyor.yml: fix Release build * yaml/libyaml#103 -- Remove unused code in yaml_document_delete * yaml/libyaml#104 -- Allow colons in plain scalars inside flow collections * yaml/libyaml#109 -- Fix comparison in tests/run-emitter.c * yaml/libyaml#117 -- Fix typo error * yaml/libyaml#119 -- The closing single quote needs to be indented... * yaml/libyaml#121 -- fix token name typos in comments * yaml/libyaml#122 -- Revert removing of open_ended after top level plain scalar * yaml/libyaml#125 -- Cherry-picks from PR 27 * yaml/libyaml#135 -- Windows/C89 compatibility * yaml/libyaml#136 -- allow override of Windows static lib name git-svn-id: svn+ssh://svn.freebsd.org/ports/head@498674 35697150-7ecd-e111-bb59-0022644237b5
Fix portlint errors in Makefile Changes in 0.2.2: * yaml/libyaml#95 -- build: do not install config.h * yaml/libyaml#97 -- appveyor.yml: fix Release build * yaml/libyaml#103 -- Remove unused code in yaml_document_delete * yaml/libyaml#104 -- Allow colons in plain scalars inside flow collections * yaml/libyaml#109 -- Fix comparison in tests/run-emitter.c * yaml/libyaml#117 -- Fix typo error * yaml/libyaml#119 -- The closing single quote needs to be indented... * yaml/libyaml#121 -- fix token name typos in comments * yaml/libyaml#122 -- Revert removing of open_ended after top level plain scalar * yaml/libyaml#125 -- Cherry-picks from PR 27 * yaml/libyaml#135 -- Windows/C89 compatibility * yaml/libyaml#136 -- allow override of Windows static lib name git-svn-id: svn+ssh://svn.freebsd.org/ports/head@498674 35697150-7ecd-e111-bb59-0022644237b5
Fix portlint errors in Makefile Changes in 0.2.2: * yaml/libyaml#95 -- build: do not install config.h * yaml/libyaml#97 -- appveyor.yml: fix Release build * yaml/libyaml#103 -- Remove unused code in yaml_document_delete * yaml/libyaml#104 -- Allow colons in plain scalars inside flow collections * yaml/libyaml#109 -- Fix comparison in tests/run-emitter.c * yaml/libyaml#117 -- Fix typo error * yaml/libyaml#119 -- The closing single quote needs to be indented... * yaml/libyaml#121 -- fix token name typos in comments * yaml/libyaml#122 -- Revert removing of open_ended after top level plain scalar * yaml/libyaml#125 -- Cherry-picks from PR 27 * yaml/libyaml#135 -- Windows/C89 compatibility * yaml/libyaml#136 -- allow override of Windows static lib name
Fix portlint errors in Makefile Changes in 0.2.2: * yaml/libyaml#95 -- build: do not install config.h * yaml/libyaml#97 -- appveyor.yml: fix Release build * yaml/libyaml#103 -- Remove unused code in yaml_document_delete * yaml/libyaml#104 -- Allow colons in plain scalars inside flow collections * yaml/libyaml#109 -- Fix comparison in tests/run-emitter.c * yaml/libyaml#117 -- Fix typo error * yaml/libyaml#119 -- The closing single quote needs to be indented... * yaml/libyaml#121 -- fix token name typos in comments * yaml/libyaml#122 -- Revert removing of open_ended after top level plain scalar * yaml/libyaml#125 -- Cherry-picks from PR 27 * yaml/libyaml#135 -- Windows/C89 compatibility * yaml/libyaml#136 -- allow override of Windows static lib name
Fix portlint errors in Makefile Changes in 0.2.2: * yaml/libyaml#95 -- build: do not install config.h * yaml/libyaml#97 -- appveyor.yml: fix Release build * yaml/libyaml#103 -- Remove unused code in yaml_document_delete * yaml/libyaml#104 -- Allow colons in plain scalars inside flow collections * yaml/libyaml#109 -- Fix comparison in tests/run-emitter.c * yaml/libyaml#117 -- Fix typo error * yaml/libyaml#119 -- The closing single quote needs to be indented... * yaml/libyaml#121 -- fix token name typos in comments * yaml/libyaml#122 -- Revert removing of open_ended after top level plain scalar * yaml/libyaml#125 -- Cherry-picks from PR 27 * yaml/libyaml#135 -- Windows/C89 compatibility * yaml/libyaml#136 -- allow override of Windows static lib name git-svn-id: svn+ssh://svn.freebsd.org/ports/head@498674 35697150-7ecd-e111-bb59-0022644237b5
Changes ======= * yaml/libyaml#95 -- build: do not install config.h * yaml/libyaml#97 -- appveyor.yml: fix Release build * yaml/libyaml#103 -- Remove unused code in yaml_document_delete * yaml/libyaml#104 -- Allow colons in plain scalars inside flow collections * yaml/libyaml#109 -- Fix comparison in tests/run-emitter.c * yaml/libyaml#117 -- Fix typo error * yaml/libyaml#119 -- The closing single quote needs to be indented... * yaml/libyaml#121 -- fix token name typos in comments * yaml/libyaml#122 -- Revert removing of open_ended after top level plain scalar * yaml/libyaml#125 -- Cherry-picks from PR 27 * yaml/libyaml#135 -- Windows/C89 compatibility * yaml/libyaml#136 -- allow override of Windows static lib name
It turns out if you read this rules file with falco versions 0.24.0 and earlier, it can't parse the bare string containing colons: (Ignore the misleading error context, that's a different problem): ``` Thu Sep 10 10:31:23 2020: Falco initialized with configuration file /etc/falco/falco.yaml Thu Sep 10 10:31:23 2020: Loading rules from file /tmp/k8s_audit_rules.yaml: Thu Sep 10 10:31:23 2020: Runtime error: found unexpected ':' --- source: k8s_audit tags: [k8s] # In a local/user rules file, you could override this macro to ``` I think the change in 0.25.0 to use a bundled libyaml fixed the problem, as it also upgraded libyaml to a version that fixed yaml/libyaml#104. Work around the problem with earlier falco releases by quoting the colon.
It turns out if you read this rules file with falco versions 0.24.0 and earlier, it can't parse the bare string containing colons: (Ignore the misleading error context, that's a different problem): ``` Thu Sep 10 10:31:23 2020: Falco initialized with configuration file /etc/falco/falco.yaml Thu Sep 10 10:31:23 2020: Loading rules from file /tmp/k8s_audit_rules.yaml: Thu Sep 10 10:31:23 2020: Runtime error: found unexpected ':' --- source: k8s_audit tags: [k8s] # In a local/user rules file, you could override this macro to ``` I think the change in 0.25.0 to use a bundled libyaml fixed the problem, as it also upgraded libyaml to a version that fixed yaml/libyaml#104. Work around the problem with earlier falco releases by quoting the colon. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
It turns out if you read this rules file with falco versions 0.24.0 and earlier, it can't parse the bare string containing colons: (Ignore the misleading error context, that's a different problem): ``` Thu Sep 10 10:31:23 2020: Falco initialized with configuration file /etc/falco/falco.yaml Thu Sep 10 10:31:23 2020: Loading rules from file /tmp/k8s_audit_rules.yaml: Thu Sep 10 10:31:23 2020: Runtime error: found unexpected ':' --- source: k8s_audit tags: [k8s] # In a local/user rules file, you could override this macro to ``` I think the change in 0.25.0 to use a bundled libyaml fixed the problem, as it also upgraded libyaml to a version that fixed yaml/libyaml#104. Work around the problem with earlier falco releases by quoting the colon. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
It turns out if you read this rules file with falco versions 0.24.0 and earlier, it can't parse the bare string containing colons: (Ignore the misleading error context, that's a different problem): ``` Thu Sep 10 10:31:23 2020: Falco initialized with configuration file /etc/falco/falco.yaml Thu Sep 10 10:31:23 2020: Loading rules from file /tmp/k8s_audit_rules.yaml: Thu Sep 10 10:31:23 2020: Runtime error: found unexpected ':' --- source: k8s_audit tags: [k8s] # In a local/user rules file, you could override this macro to ``` I think the change in 0.25.0 to use a bundled libyaml fixed the problem, as it also upgraded libyaml to a version that fixed yaml/libyaml#104. Work around the problem with earlier falco releases by quoting the colon. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
It turns out if you read this rules file with falco versions 0.24.0 and earlier, it can't parse the bare string containing colons: (Ignore the misleading error context, that's a different problem): ``` Thu Sep 10 10:31:23 2020: Falco initialized with configuration file /etc/falco/falco.yaml Thu Sep 10 10:31:23 2020: Loading rules from file /tmp/k8s_audit_rules.yaml: Thu Sep 10 10:31:23 2020: Runtime error: found unexpected ':' --- source: k8s_audit tags: [k8s] # In a local/user rules file, you could override this macro to ``` I think the change in 0.25.0 to use a bundled libyaml fixed the problem, as it also upgraded libyaml to a version that fixed yaml/libyaml#104. Work around the problem with earlier falco releases by quoting the colon. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
It turns out if you read this rules file with falco versions 0.24.0 and earlier, it can't parse the bare string containing colons: (Ignore the misleading error context, that's a different problem): ``` Thu Sep 10 10:31:23 2020: Falco initialized with configuration file /etc/falco/falco.yaml Thu Sep 10 10:31:23 2020: Loading rules from file /tmp/k8s_audit_rules.yaml: Thu Sep 10 10:31:23 2020: Runtime error: found unexpected ':' --- source: k8s_audit tags: [k8s] # In a local/user rules file, you could override this macro to ``` I think the change in 0.25.0 to use a bundled libyaml fixed the problem, as it also upgraded libyaml to a version that fixed yaml/libyaml#104. Work around the problem with earlier falco releases by quoting the colon. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
It turns out if you read this rules file with falco versions 0.24.0 and earlier, it can't parse the bare string containing colons: (Ignore the misleading error context, that's a different problem): ``` Thu Sep 10 10:31:23 2020: Falco initialized with configuration file /etc/falco/falco.yaml Thu Sep 10 10:31:23 2020: Loading rules from file /tmp/k8s_audit_rules.yaml: Thu Sep 10 10:31:23 2020: Runtime error: found unexpected ':' --- source: k8s_audit tags: [k8s] # In a local/user rules file, you could override this macro to ``` I think the change in 0.25.0 to use a bundled libyaml fixed the problem, as it also upgraded libyaml to a version that fixed yaml/libyaml#104. Work around the problem with earlier falco releases by quoting the colon. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
It turns out if you read this rules file with falco versions 0.24.0 and earlier, it can't parse the bare string containing colons: (Ignore the misleading error context, that's a different problem): ``` Thu Sep 10 10:31:23 2020: Falco initialized with configuration file /etc/falco/falco.yaml Thu Sep 10 10:31:23 2020: Loading rules from file /tmp/k8s_audit_rules.yaml: Thu Sep 10 10:31:23 2020: Runtime error: found unexpected ':' --- source: k8s_audit tags: [k8s] # In a local/user rules file, you could override this macro to ``` I think the change in 0.25.0 to use a bundled libyaml fixed the problem, as it also upgraded libyaml to a version that fixed yaml/libyaml#104. Work around the problem with earlier falco releases by quoting the colon. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
It turns out if you read this rules file with falco versions 0.24.0 and earlier, it can't parse the bare string containing colons: (Ignore the misleading error context, that's a different problem): ``` Thu Sep 10 10:31:23 2020: Falco initialized with configuration file /etc/falco/falco.yaml Thu Sep 10 10:31:23 2020: Loading rules from file /tmp/k8s_audit_rules.yaml: Thu Sep 10 10:31:23 2020: Runtime error: found unexpected ':' --- source: k8s_audit tags: [k8s] # In a local/user rules file, you could override this macro to ``` I think the change in 0.25.0 to use a bundled libyaml fixed the problem, as it also upgraded libyaml to a version that fixed yaml/libyaml#104. Work around the problem with earlier falco releases by quoting the colon. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Quote scalars with colons in flow style collection SUMMARY Older versions of libyaml and pyyaml don't support colons in scalars that appear in flow style collections. This adds quotes to the handful of cases where they are used in the integration tests. This was uncovered by downstream testing. I am only able to reproduce the problem on the supported ee-minimal-rhel8 image. I believe this is because even though pyyaml should be recent enough, it has likely been compiled against an older version of libyaml that does not have the fix. See: yaml/libyaml#104 yaml/pyyaml#45 It's worth noting that running ansible-lint --fix will undo these changes, which is how I think they were made in the first place. ISSUE TYPE Bugfix Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Bikouo Aubin Reviewed-by: GomathiselviS
Quote scalars with colons in flow style collection SUMMARY Older versions of libyaml and pyyaml don't support colons in scalars that appear in flow style collections. This adds quotes to the handful of cases where they are used in the integration tests. This was uncovered by downstream testing. I am only able to reproduce the problem on the supported ee-minimal-rhel8 image. I believe this is because even though pyyaml should be recent enough, it has likely been compiled against an older version of libyaml that does not have the fix. See: yaml/libyaml#104 yaml/pyyaml#45 It's worth noting that running ansible-lint --fix will undo these changes, which is how I think they were made in the first place. ISSUE TYPE Bugfix Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Bikouo Aubin Reviewed-by: GomathiselviS (cherry picked from commit 68fb0a3)
[PR #2014/68fb0a31 backport][stable-7] Quote scalars with colons in flow style collection This is a backport of PR #2014 as merged into main (68fb0a3). SUMMARY Older versions of libyaml and pyyaml don't support colons in scalars that appear in flow style collections. This adds quotes to the handful of cases where they are used in the integration tests. This was uncovered by downstream testing. I am only able to reproduce the problem on the supported ee-minimal-rhel8 image. I believe this is because even though pyyaml should be recent enough, it has likely been compiled against an older version of libyaml that does not have the fix. See: yaml/libyaml#104 yaml/pyyaml#45 It's worth noting that running ansible-lint --fix will undo these changes, which is how I think they were made in the first place. ISSUE TYPE Bugfix Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Mark Chappell
This is a followup to #28
See http://yaml.org/spec/1.1/#nb-plain-char(c) and the following
productions.
This commit will allow
but still fail for the following:
This will be a bit more complicated to allow.
It also still fails for this:
This shouldn't be allowed. After discussing with @flyx my understanding is
that the spec has a mistake here:
Because
nb-plain-char-out
points tons-plain-char(flow-out)
, sotheoretically this would be allowed:
I think allowing colons in the middle of a flow style scalar is a good thing,
while leaving the other cases alone for now, because they are rare and you
can then always use quotes.
Edit:
With this patch the following will be allowed, too:
While this is valid for 1.2, I'm not sure about 1.1. (Edit: I think it's valid in 1.1 too.)