Skip to content
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

YAML strings value are quoted differently if the first character is a number. #7

Open
TristanCacqueray opened this issue Jun 29, 2020 · 2 comments · May be fixed by #8
Open

YAML strings value are quoted differently if the first character is a number. #7

TristanCacqueray opened this issue Jun 29, 2020 · 2 comments · May be fixed by #8

Comments

@TristanCacqueray
Copy link

The context for this is dhall-lang/dhall-haskell#1894 where I am wondering if a string value that contains a single word could always be quoted. This would enable a nicer output when the values are checksum, for example:

- checksum: "72b6ae7b4ed0"
- checksum: "e3c1b309d920"

Instead of the current output:

- checksum: "72b6ae7b4ed0"
- checksum: e3c1b309d920

Another odd behavior is regarding single vs double quote on this output:

ip: '127.0.0.1'
net: "127.0.0.1/8"
@patrickmn
Copy link
Member

Hi @TristanCacqueray,

What to quote, when, and how, is very much a balancing act. We've gone back and forth many times (including on whether to quote single/simple words), and what we have now is the combination that seems the least upsetting.

I think going back to quoting single words to accommodate the checksum example would not be worth it, as it would make common outputs like this very hard to read:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: foo
  name: "{{ .Release.Name }}-deployment"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: foo
  template:
    metadata:
      labels:
        app: foo
      name: "{{ .Release.Name }}-pod"
    spec:
      containers:
        - command:
            - /data/bin/foo
            - "--port=7654"
          image: ubuntu:latest
          name: "{{ .Release.Name }}-container"
          ports:
            - containerPort: 7654
          script: |
            #!/bin/bash
            echo hello world
          volumeMounts:
            - mountPath: /data/mount1
              name: "{{ .Release.Name }}-volume-mount1"
            - mountPath: /data/mount2
              name: "{{ .Release.Name }}-volume-mount2"

Single words are specifically not quoted to make this kind of output look familiar.

The second example of an IP vs. IP/CIDR is an oddity, yeah. It's because we know it's safe to single-quote the first string, whereas the latter has symbols and we fall back to Aeson's encoding which is double-quoted. I would be happy to accept a PR that makes CIDR strings single-quoted so that those two are at least consistent.

Might I also suggest using encodeQuoted (quoted in https://hackage.haskell.org/package/dhall-json-1.7.0/docs/Dhall-JSON-Yaml.html#t:Options or --quoted in dhall-to-yaml)? That should make the quoting quite consistent.

@TristanCacqueray
Copy link
Author

I agree the current status-quo is the least upsetting. I'll have a look to add a special case for IP/CIDR.

Thank you for the detailed feedback.

TristanCacqueray added a commit to TristanCacqueray/aeson-yaml that referenced this issue Jul 3, 2020
This change makes CIDR string encoded using the same quote as IP address.

Fixes clovyr#7
@TristanCacqueray TristanCacqueray linked a pull request Jul 3, 2020 that will close this issue
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 a pull request may close this issue.

2 participants