Skip to content

Commit c6068b4

Browse files
add validation to chars_to_stream/3, cleanup test
1 parent c4c149e commit c6068b4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/lib/charsio.pl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308

309309
% invalid continuation byte
310310
% each remaining continuation byte (if any) will raise 0xFFFD too
311-
continuation(_, ['\xFFFD\'|T], _) --> [_], decode_utf8(T).
311+
continuation(_, ['\xFFFD\'|T], _) --> [_], decode_utf8(T). %'
312312

313313
%% get_line_to_chars(+Stream, -Chars, +InitialChars).
314314
%
@@ -425,6 +425,7 @@
425425

426426
chars_to_stream(Chars, Stream, StreamOpts) :-
427427
parse_stream_options(StreamOpts, [Alias, EOFAction, Reposition, Type]),
428+
validate_chars(Chars, Type),
428429
'$memory_stream'(Stream),
429430
'$set_stream_options'(Stream, Alias ,EOFAction, Reposition, Type),
430431
( Type=binary
@@ -505,3 +506,15 @@
505506
).
506507

507508
select_rightmost_options([], []).
509+
510+
511+
valid_byte_(Byte) :-
512+
must_be(integer, Byte),
513+
Byte >= 0,
514+
Byte < 256.
515+
516+
validate_chars_(Chars, binary) :-
517+
maplist(valid_byte, Chars).
518+
519+
validate_chars_(Chars, text) :-
520+
must_be(chars, Chars).

src/tests/charsio.pl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
:- module(charsio_tests, []).
2-
:- use_module(library(os)).
3-
:- use_module(library(iso_ext)).
4-
:- use_module(library(debug)).
52
:- use_module(library(lists)).
63
:- use_module(library(charsio)).
74

0 commit comments

Comments
 (0)