Skip to content

Commit d1e3169

Browse files
committed
FIX: to word! accepting delimiters in the input string
resolves: Oldes/Rebol-issues#2444 related to: Oldes/Rebol-issues#1167
1 parent a81b862 commit d1e3169

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/core/l-scan.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,12 @@ extern REBSER *Scan_Full_Block(SCAN_STATE *scan_state, REBYTE mode_char);
17961796

17971797
Init_Scan_State(&scan_state, cp, len);
17981798

1799-
if (TOKEN_WORD == Scan_Token(&scan_state)) return Make_Word(cp, len);
1799+
if (TOKEN_WORD == Scan_Token(&scan_state)
1800+
// check also if there are not any chars left
1801+
// https://github.com/Oldes/Rebol-issues/issues/2444
1802+
// (space and tab chars at tail are truncated and so accepted)
1803+
&& scan_state.end == scan_state.limit)
1804+
return Make_Word(cp, len);
18001805

18011806
return 0;
18021807
}

src/tests/units/word-test.r3

+27
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,33 @@ Rebol [
3737
--assert word? try [to word! /1]
3838
;TODO: write mold test... should be molded to: #[word! "1"]
3939

40+
--test-- "to word! string!"
41+
;@@ https://github.com/Oldes/Rebol-issues/issues/2444
42+
find-nonloadable-words: function [][
43+
nlw: copy []
44+
for n 0 255 1 [
45+
w: copy []
46+
append w rejoin ["" to char! n "a"] ;; test as leading letter
47+
append w rejoin ["a" to char! n ] ;; test as trailing letter
48+
append w rejoin ["a" to char! n "a"] ;; test as mid letter
49+
foreach c w [
50+
if not error? try [to word! c][ ;; test only those that can be to-worded
51+
s: join trim/tail c ": 999" ;; trimmed for "a^-" and "a " inputs (allowed)
52+
if any [
53+
error? try [unset? load s] ;; Can we load it?
54+
error? try [unset? do s] ;; Can we do the assign a: 999 ?
55+
unset? do s ;; Did we get 999 if we did?
56+
999 <> do s
57+
][
58+
append nlw c ;; none of the above: it's not a serialisable word
59+
]
60+
]
61+
]
62+
]
63+
nlw
64+
]
65+
--assert empty? find-nonloadable-words
66+
4067

4168
===end-group===
4269

0 commit comments

Comments
 (0)