From 8b4a5e9919dfec2dc46d51d5ea6ef56b74171d7e Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 22 Apr 2016 11:20:57 +1000 Subject: [PATCH] Split YAML & JSON parsing It turns out that invalid JSON can be valid YAML ... thus if you mess up a pkg-map file that still works as a YAML file dib-lint will let it pass, but when pkg-map later tries to open it as a JSON file, it fails. Parse each type separately to catch these problems. Change-Id: Ib3985e7d1599ed6bf3b7a73b786a53177b71fae0 --- bin/dib-lint | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/bin/dib-lint b/bin/dib-lint index ca9df80cf..ced05e457 100755 --- a/bin/dib-lint +++ b/bin/dib-lint @@ -176,27 +176,35 @@ if ! excluded mddocs; then fi fi -echo "Checking YAML & JSON parsing" - -for i in $(find elements -name '*.yaml' \ - -o \( -name pkg-map -type f -a \! -executable \)); do +echo "Checking YAML parsing..." +for i in $(find elements -type f -name '*.yaml'); do + echo "Parsing $i" py_check=" -import json import yaml import sys -try: - objs = json.load(open('$i')) - sys.exit(0) -except ValueError: - pass try: objs = yaml.load(open('$i')) - sys.exit(0) except yaml.parser.ParserError: - pass -sys.exit(1)" + sys.exit(1) +" if ! python -c "$py_check"; then - error "$i is not a valid yaml/json file" + error "$i is not a valid YAML file" + fi +done +echo "Checking pkg-map files..." +for i in $(find elements -type f \ + -name 'pkg-map' -a \! -executable); do + echo "Parsing $i" + py_check=" +import json +import sys +try: + objs = json.load(open('$i')) +except ValueError: + sys.exit(1) +" + if ! python -c "$py_check"; then + error "$i is not a valid JSON file" fi done