question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to disable some features from SnakeYaml

See original GitHub issue

(by @exbe https://github.com/FasterXML/jackson-dataformat-yaml/issues/85)

SnakeYaml converts some string values into Boolean while resolving input (link)

 public static final Pattern BOOL = Pattern.compile("^(?:yes|Yes|YES|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)$");

While it is useful feature, some yamls might be converted with wrong value. Think about country code “NO”, which is Norway.

Is there a way to disable or have better control over this with YamlParser features?

PS Workaround is simple, just surround value with quotes, e.g.

countries:
    - AU
    - "NO"
    - MOON

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
asomovcommented, Oct 29, 2020

@jeff-miller-cfa I think it should be only true|false (this is also the default in snakeyaml-engine now)

1reaction
jeff-miller-cfacommented, Oct 29, 2020

a workaround to this is to create a custom Resolver then override the addImplicitResolver method like below:

new Resolver() {
        @Override public void addImplicitResolver(Tag tag, Pattern regexp, String first) {
            if (tag.equals(Tag.BOOL)) {
                regexp = Pattern.compile("^(?:true|True|TRUE|false|False|FALSE)$");
                first = "tTfF";
            }
            super.addImplicitResolver(tag, regexp, first);
        }
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved - YAML anchors and aliases - how to disable them?
Hello, as in title, im wondering if there is an easy way of disabling anchors and aliases that happens to show up in...
Read more >
Preventing YAML parsing vulnerabilities with snakeyaml in Java
The outdated version of snakeyaml contains a Denial of Service vulnerability. We highly recommend that you update snakeyaml to version 1.26 or ...
Read more >
How to hide bean type in snakeyaml - Stack Overflow
Use org.yaml.snakeyaml.representer.Representer , set Tag.MAP to hide the root tag. Representer representer = new Representer(); representer.
Read more >
How to ignore unknown local tags - snakeyaml - Bitbucket
I have some YAMl files that I need to manipulate. Unfortunately, the YAML contains local tags that can not be resolved to classes....
Read more >
YAML anchors and aliases and how to disable them |
PyYAML does not have built-in setting allowing disabling of the default behaviour. Fortunately there are two ways in which we can prevent ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found