XML missing encoding error

db4
Daniel Ehrenberg 2009-03-18 18:32:34 -05:00
parent 2aa7df0e55
commit a282789910
3 changed files with 16 additions and 3 deletions

View File

@ -3,7 +3,7 @@
USING: kernel namespaces xml.name io.encodings.utf8 xml.elements
io.encodings.utf16 xml.tokenize xml.state math ascii sequences
io.encodings.string io.encodings combinators accessors
xml.data io.encodings.iana ;
xml.data io.encodings.iana xml.errors ;
IN: xml.autoencoding
: decode-stream ( encoding -- )
@ -35,7 +35,10 @@ IN: xml.autoencoding
: prolog-encoding ( prolog -- )
encoding>> dup "UTF-16" =
[ drop ] [ name>encoding [ decode-stream ] when* ] if ;
[ drop ] [
dup name>encoding
[ decode-stream ] [ bad-encoding ] ?if
] if ;
: instruct-encoding ( instruct/prolog -- )
dup prolog?

View File

@ -1,5 +1,5 @@
USING: continuations xml xml.errors tools.test kernel arrays
xml.data quotations fry ;
xml.data quotations fry byte-arrays ;
IN: xml.errors.tests
: xml-error-test ( expected-error xml-string -- )
@ -40,3 +40,4 @@ T{ bad-doctype f 1 22 T{ opener { name T{ name f "" "foo" "" } } { attrs T{ attr
T{ disallowed-char f 1 4 1 } "<x>\u000001</x>" xml-error-test
T{ missing-close f 1 8 } "<!-- foo" xml-error-test
T{ misplaced-directive f 1 9 "ENTITY" } "<!ENTITY foo 'bar'><x/>" xml-error-test
[ "<?xml version='1.0' encoding='foobar'?>" >byte-array bytes>xml ] [ T{ bad-encoding f 1 39 "foobar" } = ] must-fail-with

View File

@ -338,5 +338,14 @@ TUPLE: bad-doctype < xml-error-at contents ;
M: bad-doctype summary
call-next-method "\nDTD contains invalid object" append ;
TUPLE: bad-encoding < xml-error-at encoding ;
: bad-encoding ( encoding -- * )
\ bad-encoding xml-error-at
swap >>encoding
throw ;
M: bad-encoding summary
call-next-method
"\nEncoding in XML document does not exist" append ;
UNION: xml-error
multitags notags pre/post-content xml-error-at ;