Blacksmoke16 / oq

A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.
https://blacksmoke16.github.io/oq/
MIT License
190 stars 15 forks source link

Prevent invalid XML output #9

Closed nichtich closed 5 years ago

nichtich commented 5 years ago

I think this is not intended:

echo '{ "a b=\"c\"": {} }' | oq -o xml .
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <a b="c"/>
</root>

Disallowed XML element and attribute names should result in a error. The format to check against is defined here and discussed here. Note that names starting with xml: should also be allowed.

Blacksmoke16 commented 5 years ago

Sorry if im missing something here, but isn't that valid XML? I ran it through some linters and didn't get any errors. However, based on the link you provided I think

echo '{ "1 b=\"c\"": {} }' | ./bin/oq -o xml .
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <1 b="c"/>
</root>

should error since a number is not a valid start character.

nichtich commented 5 years ago
echo '{ "a b=\"c\"": "" }' | oq -o xml .
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <a b="c"></a b="c">
</root>
Blacksmoke16 commented 5 years ago

@nichtich This is actually an issue in Crystal stdlib, I create https://github.com/crystal-lang/crystal/issues/7963 to deal with it and will have a PR for it soon.

In that case there is nothing to do in oq itself, and will just start working as intended after its merged and the next version of Crystal is released.

EDIT: Examples

echo '{ "1": {} }' | ./bin/oq -o xml .
oq error: Invalid element name: '1'
echo '{ "a b=\"c\"": {} }' | ./bin/oq -o xml .
oq error: Invalid element name: 'a b="c"'
Blacksmoke16 commented 5 years ago

Er, I'll keep this open until its fixed on Crystal's end. Would at least allow building from source to get the feature.