yaml / yaml/libyaml

How to output simple keys regardless of length ("128 chars hardcoded limit")

Open Beginner friendly
#340 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
1.2k
Forks
370
PR merge metrics
No merged PRs in 30d

Description

  1. How to output YAML (from Ruby) with simple keys regardless of length?
  2. What is the rationale for the (hard-coded) limit of 128 chars? (Include reference to standard)
require 'psych'

%w[
  https://example.com/this-url-shy-of-one-hundred-and-twenty-eight-characters-causes-libyaml-not-to-prefix-it-with-a-question-mark
  https://example.com/this-url-longer-than-one-hundred-and-twenty-eight-characters-causes-libyaml-to-prefix-it-with-a-question-mark
].to_h { [it, it.length] }.to_yaml(line_width: -1).then { puts it }
---
https://example.com/this-url-shy-of-one-hundred-and-twenty-eight-characters-causes-libyaml-not-to-prefix-it-with-a-question-mark: 128
? https://example.com/this-url-longer-than-one-hundred-and-twenty-eight-characters-causes-libyaml-to-prefix-it-with-a-question-mark
: 129

https://github.com/yaml/libyaml/blob/master/src/emitter.c#L1187

yaml_emitter_check_simple_key(yaml_emitter_t *emitter)
<snip>
    if (length > 128)
        return 0;

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start with src/emitter.c at yaml_emitter_check_simple_key(), especially the 128-character check, and reproduce the behavior using the Ruby/Psych example in the issue. Check the YAML standard reference relevant to simple keys and document the rationale and whether libyaml provides a way to emit these keys without the question-mark indicator.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, yaml
Domain
tooling
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.