Skip to content

Commit f444421

Browse files
committed
FIX: SAVE broken with .txt suffix
Fixes: metaeducation/rebol-issues#1755
1 parent 7b9e655 commit f444421

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/mezz/sys-codec.r

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ decode: function [
6161
encode: function [
6262
{Encodes a datatype (e.g. image!) into a series of bytes.}
6363
type [word!] {Media type (jpeg, png, etc.)}
64-
data [image! binary! string!] {The data to encode}
64+
data {The data to encode}
6565
/options opts [block!] {Special encoding options}
6666
][
6767
unless all [
6868
cod: select system/codecs type
6969
data: either handle? try [cod/entry] [
7070
; original codecs were only natives
71+
if type = 'text [
72+
return either binary? data [to string! data][form data]
73+
]
7174
do-codec cod/entry 'encode data
7275
][
7376
either function? try [:cod/encode][

src/tests/units/codecs-test.r3

+27
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@ Rebol [
1414
--assert 'text = encoding? #{6162}
1515
===end-group===
1616

17+
===start-group=== "TEXT codec"
18+
--test-- "ENCODE text"
19+
--assert "1 2" = encode 'text [1 2]
20+
--assert "1 2" = encode 'text #{312032}
21+
--test-- "SAVE %test.txt"
22+
--assert [1 2] = load save %temp.bin [1 2]
23+
--assert "1 2" = load save %temp.txt [1 2] ;-- note that result is STRING
24+
--assert "#{312032}^/" = read/string %temp.bin ;@@ should be there the newline char?!
25+
--assert "1 2" = read/string %temp.txt
26+
delete %temp.bin
27+
delete %temp.txt
28+
29+
===end-group===
30+
31+
===start-group=== "Invalid SAVE"
32+
--test-- "invalid image SAVE"
33+
--assert error? try [save %temp.bmp [1 2]]
34+
--assert error? try [save %temp.png [1 2]]
35+
--assert error? try [save %temp.jpg [1 2]]
36+
--assert error? try [save %temp.bmp "foo"]
37+
--assert error? try [save %temp.png "foo"]
38+
--assert error? try [save %temp.jpg "foo"]
39+
--assert error? try [save %temp.bmp #{00}]
40+
--assert error? try [save %temp.png #{00}]
41+
--assert error? try [save %temp.jpg #{00}]
42+
43+
1744
if find system/codecs 'wav [
1845
system/codecs/wav/verbose: 3
1946
===start-group=== "WAV codec"

0 commit comments

Comments
 (0)