为什么这个简单的YAML无法正确解析或验证?

时间:2015-12-18 20:26:16

标签: yaml lint pyyaml

这不会在几个不同的YAML验证器中验证。如果通过PyYAML读取它也无法解析。这只是无效的YAML吗?

---
databases:
  - name: mydb
    migrations:
      - type: liquibase
        file: 1.xml
      - type: liquibase
        file: 2.xml

例如,YAMLlint会产生以下错误:

(<unknown>): mapping values are not allowed in this context at line 6 column 13

1 个答案:

答案 0 :(得分:1)

这非常烦人,与地图结构列表无关。不知何故,那里有空格字符,这些字符不是ASCII,PyYAML和我试过的验证器都不能很好地应对。

$ xxd foobar.txt 
00000000: 2d2d 2d0a 6461 7461 6261 7365 733a 0a20  ---.databases:. 
00000010: 202d 206e 616d 653a 206d 7964 620a e280   - name: mydb...
00000020: 8220 e280 8220 6d69 6772 6174 696f 6e73  . ... migrations
00000030: 3a0a e280 8220 e280 8220 e280 8220 2d20  :.... ... ... - 
00000040: 7479 7065 3a20 6c69 7175 6962 6173 650a  type: liquibase.
00000050: 2020 2020 2020 2020 6669 6c65 3a20 312e          file: 1.
00000060: 786d 6c0a e280 8220 e280 8220 e280 8220  xml.... ... ... 
00000070: 2d20 7479 7065 3a20 6c69 7175 6962 6173  - type: liquibas
00000080: 650a 2020 2020 2020 2020 6669 6c65 3a20  e.        file: 
00000090: 322e 786d 6c0a                           2.xml.

查看那些e28082&#39;他们是空间角色。