From 187de8b0ab54d7cd83ab1901b7fb44c7060aebd5 Mon Sep 17 00:00:00 2001 From: George Hansper Date: Sat, 3 Dec 2022 15:06:55 +1100 Subject: [PATCH] Allow unmatched square-brackets in values (#782) Co-authored-by: George Hansper --- src/augrun.c | 2 +- tests/root/var/tmp/test-quoted-strings.txt | 1 + tests/test-augtool/quoted-strings.sh | 35 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/root/var/tmp/test-quoted-strings.txt create mode 100644 tests/test-augtool/quoted-strings.sh diff --git a/src/augrun.c b/src/augrun.c index f12d28470..97626471b 100644 --- a/src/augrun.c +++ b/src/augrun.c @@ -176,7 +176,7 @@ static char *nexttoken(struct command *cmd, char **line, bool path) { if (nescaped == 0) { if (*s == '[') nbracket += 1; if (*s == ']') nbracket -= 1; - if (nbracket < 0) { + if (nbracket < 0 && path) { ERR_REPORT(cmd, AUG_ECMDRUN, "unmatched ["); return NULL; } diff --git a/tests/root/var/tmp/test-quoted-strings.txt b/tests/root/var/tmp/test-quoted-strings.txt new file mode 100644 index 000000000..a9b378e15 --- /dev/null +++ b/tests/root/var/tmp/test-quoted-strings.txt @@ -0,0 +1 @@ +find this: ]][ )( . * $ / \ diff --git a/tests/test-augtool/quoted-strings.sh b/tests/test-augtool/quoted-strings.sh new file mode 100644 index 000000000..27e0fb312 --- /dev/null +++ b/tests/test-augtool/quoted-strings.sh @@ -0,0 +1,35 @@ +#!/bin/bash +#insert after /files/tmp/test-quoted-strings.txt/*[. =~ regexp('find.*')] 'found [' +commands=" +set /files/var/tmp/test-quoted-strings.txt/01 '[' +set /files/var/tmp/test-quoted-strings.txt/02 ']' +set /files/var/tmp/test-quoted-strings.txt/03 '][' +set /files/var/tmp/test-quoted-strings.txt/04 '[]' +set /files/var/tmp/test-quoted-strings.txt/05 '[][' +set /files/var/tmp/test-quoted-strings.txt/06 '[]]' +set /files/var/tmp/test-quoted-strings.txt/07 '(' +set /files/var/tmp/test-quoted-strings.txt/08 ')' +set /files/var/tmp/test-quoted-strings.txt/09 '"\""' +insert 010 after /files/var/tmp/test-quoted-strings.txt/seq::*[.=~regexp('.*\]\]\[ \)\( .*')] +set /files/var/tmp/test-quoted-strings.txt/010 'found ]][ )(' +insert 011 after /files/var/tmp/test-quoted-strings.txt/seq::*[.=~regexp('.*\\\..*')] +set /files/var/tmp/test-quoted-strings.txt/011 'found .' +" +lens=Simplelines.lns +file="/var/tmp/test-quoted-strings.txt" + +diff='--- /var/tmp/test-quoted-strings.txt ++++ /var/tmp/test-quoted-strings.txt.augnew +@@ -1 +1,12 @@ + find this: ]][ )( . * $ / \ ++found . ++found ]][ )( ++[ ++] ++][ ++[] ++[][ ++[]] ++( ++) ++"'