Sfoglia il codice sorgente

Replace YAML-unsafe characters with �

Things like control character would invalidate whole report.  If user
needs verbatim, jat__submit() shall do that.
Alois Mahdal 6 anni fa
parent
commit
f7f5fb3edf
1 ha cambiato i file con 31 aggiunte e 5 eliminazioni
  1. 31
    5
      src/jat.sh.skel

+ 31
- 5
src/jat.sh.skel Vedi File

@@ -1321,11 +1321,12 @@ __jat__writelog() {
1321 1321
     #
1322 1322
     # Write logged output (copy if needed)
1323 1323
     #
1324
-    case $JAT__YLOG in
1325
-        "") cat >> "$__JAT__SDIR/log.yaml" ;;
1326
-        -)  tee -a "$__JAT__SDIR/log.yaml" ;;
1327
-        *)  tee -a "$__JAT__SDIR/log.yaml" >> "$JAT__YLOG" ;;
1328
-    esac
1324
+    __jat__strip4yaml \
1325
+      | case $JAT__YLOG in
1326
+            "") cat >> "$__JAT__SDIR/log.yaml" ;;
1327
+            -)  tee -a "$__JAT__SDIR/log.yaml" ;;
1328
+            *)  tee -a "$__JAT__SDIR/log.yaml" >> "$JAT__YLOG" ;;
1329
+        esac
1329 1330
 }
1330 1331
 
1331 1332
 __jat__valid_beid() {
@@ -1344,6 +1345,31 @@ __jat__valid_pair() {
1344 1345
     grep -qx '\([tor][.]\)\?[[:alpha:]_][[:alnum:]_]*=.*' <<<"$tainted"
1345 1346
 }
1346 1347
 
1348
+__jat__strip4yaml() {
1349
+    #
1350
+    # Replace yaml-invalid characters
1351
+    #
1352
+    # Yaml won't allow all characters:
1353
+    #
1354
+    # > [...] The allowed character range explicitly excludes the C0 control
1355
+    # > block #x0-#x1F (except for TAB #x9, LF #xA, and CR #xD which are
1356
+    # > allowed), DEL #x7F, the C1 control block #x80-#x9F (except for NEL
1357
+    # > #x85 which is allowed), the surrogate block #xD800-#xDFFF, #xFFFE,
1358
+    # > and #xFFFF.
1359
+    #
1360
+    # so take stdin and replace all unacceptable characters with '�'.
1361
+    #
1362
+    local bad           # perl 'tr///' range of bad characters
1363
+    local repl='�'      # replacement char
1364
+    bad+='\N{U+0}-\N{U+8}\N{U+B}\N{U+C}\N{U+E}-\N{U+1F}'    # C0 with some gaps
1365
+    bad+='\N{U+7F}'                                         # DEL alone
1366
+    bad+='\N{U+80}-\N{U+84}\N{U+86}-\N{U+9F}'               # C1 with NEL gap
1367
+    #   bad+='\N{U+D800}-\N{U+DFFF}'                        # surrogates
1368
+    #   bad+='\N{U+FFFE}-\N{U+FFFF}'                        # 0xFFFE and 0xFFFF
1369
+    #FIXME: for some reasons perl complains about these ^^
1370
+    perl -CS -Mutf8 -pe "tr/$bad/$repl/"
1371
+}
1372
+
1347 1373
 __jat__yamls() {
1348 1374
     #
1349 1375
     # Print a scalar field named $1 with value $2