]> gitweb.factorcode.org Git - factor.git/commitdiff
io.encodings.string: ensure encoded string is a byte-array
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 22 Feb 2024 03:19:33 +0000 (21:19 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 22 Feb 2024 03:19:33 +0000 (21:19 -0600)
basis/io/encodings/string/string-tests.factor
basis/io/encodings/string/string.factor

index 62f65e5c3e1455354ae6c3a2a839b431e0edeaa1..0acd7bd6ecad96708596f8294c49da06911a9087 100644 (file)
@@ -9,3 +9,6 @@ io.encodings.string tools.test io.encodings.binary ;
 
 { "hello" } [ "hello" utf8 encode >string ] unit-test
 { "\0h\0e" } [ "he" utf16be encode >string ] unit-test
+
+{ B{ 97 98 99 } } [ "abc" binary encode ] unit-test
+{ B{ 97 98 99 } } [ "abc" utf8 encode ] unit-test
index b62ef9aa18efb9be6c752026b58c3f795afaf559..4b5d3067bf98f5c45ab267d771a2aed7e1602e57 100644 (file)
@@ -19,7 +19,7 @@ IN: io.encodings.string
     ] if ; inline
 
 :: encode ( string encoding -- byte-array )
-    encoding binary eq? [ string ] [
+    encoding binary eq? [ string B{ } like ] [
         string aux>> not encoding { ascii utf8 } member-eq? and [
             string string>byte-array-fast
         ] [