`YAMLSchema.CORE` decodes YAML 1.2 base-10 integers with leading zeros as legacy octals

Open
#754 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
backend

Research direction

Start by tracing YAML integer parsing under YAMLSchema.CORE in the YAML dataformat module; the issue does not name implementation files or tests. Reproduce with the provided YAMLMapper example using val: 0640, then find or add a focused regression test. Done means the parsed value is decimal 640 under the Core Schema while other integer formats remain correct.

Written by the indexing model from the issue text.

Description

yaml

When using Jackson 3.x with YAMLSchema.CORE (which implements YAML 1.2 Core Schema rules), numbers with leading zeros (e.g., 0640) are correctly classified as numbers, since YAML 1.2 dropped the YAML 1.1 leading zero requirement for octals (octals in 1.2 use 0o). However, Jackson subsequently decodes the number using legacy Java octal rules, resulting in the decimal value 416 instead of 640.

In the YAML 1.2 Core Schema, the integer regex is [-+]? [0-9]+. Therefore, 0640 is a valid base-10 integer and should evaluate to 640.

Reproducing the Issue

pom.xml

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>yamltest</artifactId>
    <version>1.0.0</version>
    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>tools.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>3.2.3</version>
        </dependency>
        <dependency>
            <groupId>tools.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
            <version>3.2.3</version>
        </dependency>
    </dependencies>
</project>

Main.java

import tools.jackson.databind.JsonNode;
import tools.jackson.dataformat.yaml.YAMLMapper;
import tools.jackson.dataformat.yaml.YAMLSchema;
import tools.jackson.dataformat.yaml.YAMLFactory;

public class Main {
    public static void main(String[] args) throws Exception {
        YAMLMapper mapper = YAMLMapper.builder(
            YAMLFactory.builder().yamlSchema(YAMLSchema.CORE).build()
        ).build();
        
        JsonNode node = mapper.readTree("val: 0640");
        
        System.out.println("Parsed Value: " + node.get("val").asInt());
        // Expected: 640
        // Actual: 416
    }
}

Expected Behavior

The node should evaluate to the base-10 integer 640.

Actual Behavior

The node evaluates to 416 (octal conversion of 0640).

Dominant language
Java
Stars
454
Forks
176
Avg merge
2d 8h
Merged PRs (30d)
16

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from FasterXML/jackson-dataformats-text

All issues in FasterXML/jackson-dataformats-text

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.