mikefarah / yq

yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
https://mikefarah.gitbook.io/yq/
MIT License
12.37k stars 603 forks source link

Yaml file with regex is parsed with invalid characters in json format on s390x platform (>v4.35.2) #2093

Open chegde20121 opened 4 months ago

chegde20121 commented 4 months ago

Describe the bug When I parse a yaml file which contains regex with escape characters into json format on s390x platform, Note that any how to questions should be posted in the discussion board and not raised as an issue.

On s390x:- version: v4.44.2 Platform: s390x input yaml:-

divisor:
  anyOf:
  - type: integer
  - type: string
  description: Specifies the output format of the exposed resources, defaults to "1"
  pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
  x-kubernetes-int-or-string: true
./yq_linux_s390x eval -o=json postgres_edb.yaml > postgres_edb.json
jq . postgres_edb.json
parse error: Invalid escape at line 1989, column 165

Parsed line from yq in s390x is

Actual Output:-

 "pattern": "^(\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$",

On x86 version: v4.44.2 Platform: x86 input yaml:-

divisor:
  anyOf:
  - type: integer
  - type: string
  description: Specifies the output format of the exposed resources, defaults to "1"
  pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
  x-kubernetes-int-or-string: true

command:

./bin/yq eval -o=json postgres_edb.yaml > postgres_edb.json

Output

 "pattern": "^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$"

In x86 there is no issue. But only in s390x the yaml with escape charecters is not parsed as expected

Command The command you ran:

./yq_linux_s390x eval -o=json postgres_edb.yaml > postgres_edb.json

Actual behavior

"pattern": "^(\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$"

Expected behavior

 "pattern": "^(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))))?$"


**Additional context**
This issue is occurring in all the versions above v4.35.2 of s390x distribution
mikefarah commented 4 months ago

Weird - I'm not doing anything special for s390x other than using the go-compiler to build the binary. So you're saying it produces a different JSON output to the x86 binary?