Skip to content

Commit

Permalink
FIX: Cause an error in PARSE for invalid args to TO
Browse files Browse the repository at this point in the history
Previously, PARSE over string input would silently ignore invalid
arguments to TO. With this fix, invalid args to TO correctly cause an
error:
```
    >> parse "foo" [to 1.2]
    ** Script error: PARSE - invalid rule or usage of rule: to
    ** Where: parse
    ** Near: parse "foo" [to 1.2]
```
The problem was identified via static code analysis with Cppcheck.

(cherry picked from rebol#204)
fixes: Oldes/Rebol-issues#2129
  • Loading branch information
Oldes committed Nov 2, 2020
1 parent bd42e74 commit 145ac8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/u-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
i = Find_Str_Bitset(series, 0, index, series->tail, 1, VAL_BITSET(item), HAS_CASE(parse));
if (i != NOT_FOUND && is_thru) i++;
}
else
Trap1(RE_PARSE_RULE, item - 1);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/tests/units/parse-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ Rebol [
--assert not parse "ba" [to a "ba"]
--assert parse/case "a" [thru a]
--assert not parse/case "A" [thru a]
--test-- "TO/THRU with unsuported rule"
;@@ https://github.com/Oldes/Rebol-issues/issues/2129
--assert all [
e: try [parse "foo" [thru some "0"]] ;@@ Red supports `some` right after `to`!
e/id = 'parse-rule
]
--assert all [
e: try [parse "foo" [thru 1.2]]
e/id = 'parse-rule
]


===end-group===
Expand Down

0 comments on commit 145ac8f

Please sign in to comment.