Skip to content

Commit 067fee5

Browse files
committed
FIX: Length-specified script embedding
resolves: Oldes/Rebol-issues#1941
1 parent 5ae4871 commit 067fee5

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/mezz/sys-load.reb

+4-2
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,9 @@ load: function [
323323

324324
;-- Try to load the header, handle error:
325325
not all [
326-
set [hdr: data:] either object? data [load-ext-module data] [load-header data]
326+
set [hdr: data: end:] either object? data [load-ext-module data] [load-header data]
327327
if word? hdr [cause-error 'syntax hdr source]
328+
unless tail? end [data: copy/part data end]
328329
]
329330
; data is binary or block now, hdr is object or none
330331

@@ -537,7 +538,8 @@ load-module: function [
537538
; Get and process the header
538539
not hdr [
539540
; Only happens for string, binary or non-extension file/url source
540-
set [hdr: code:] load-header/required data
541+
set [hdr: code: end:] load-header/required data
542+
unless tail? end [code: copy/part code end]
541543
case [
542544
word? hdr [cause-error 'syntax hdr source]
543545
import none ; /import overrides 'delay option

src/tests/units/load-test.r3

+8-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ Rebol [
6060
--assert block? b: load ["print 'hello" "print 'there"]
6161
--assert [print 'hello] = b/1
6262
--assert [print 'there] = b/2
63+
64+
--test-- "Length-specified script embedding"
65+
;@@ https://github.com/Oldes/Rebol-issues/issues/1941
66+
--assert [print "hello"] = load {rebol [length: 14] print "hello" other stuff}
67+
--assert 1 = try [do {rebol [length: 2] 1 other stuff}]
68+
--assert [lib-local a] = words-of import {rebol [length: 5] a: 1 b: 2 print "evil code"}
69+
--assert [lib-local a] = words-of import/check {rebol [length: 5 checksum: #{E9A16FDEC8FF093599E2AA10C30D2D98D1C541C5}] a: 1 b: 2 print "evil code"} #{E9A16FDEC8FF093599E2AA10C30D2D98D1C541C5}
70+
6371
--test-- "issue-858"
6472
;@@ https://github.com/Oldes/Rebol-issues/issues/858
6573
--assert [<] = load mold [ < ]
@@ -78,7 +86,6 @@ Rebol [
7886

7987
===end-group===
8088

81-
8289
===start-group=== "find-script native"
8390
--test-- "find-script"
8491
;@@ https://github.com/Oldes/Rebol-issues/issues/182

0 commit comments

Comments
 (0)