Problems with 'build-tag
[1/1] from: al::bri::xtra::co::nz at: 8-Jun-2002 0:33
I've noticed some problems with Rebol's standard 'build-tag. Here's what it
does wrong:
Test failed!
Input: [input "checked" type "radio" name "Favourite" value "cat"]
Result: {<input="checked" type="radio" name="Favourite" value="cat">}
Correct: {<input checked type="radio" name="Favourite" value="cat">}
Test failed!
Input: [html xml:lang "en"]
Result: {<html="xml:lang"="en">}
Correct: {<html xml:lang="en">}
Test failed!
Input: [body text #FF80CC]
Result: {<body text="FF80CC">}
Correct: {<body text="#FF80CC">}
Test failed!
Input: [a href %Test File Space.txt]
Result: {<a href="Test File Space.txt">}
Correct: {<a href="Test File Space.txt">}
Test failed!
Input: [/html gibber %Froth.txt]
Result: {</html gibber="Froth.txt">}
Correct: "</html>"
Test failed!
Input: [?xml version "1.0" encoding "UTF-8"]
Result: {<?xml version="1.0" encoding="UTF-8">}
Correct: {<?xml version="1.0" encoding="UTF-8"?>}
Test failed!
Input: [html xmlns http://www.w3.org/1999/xhtml xml:lang "en" lang
en
]
Result: {<html xmlns="http://www.w3.org/1999/xhtml"="xml:lang"="en"
lang="en">}
Correct: {<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">}
Test failed!
Input: [html xmlns http://www.w3.org/1999/xhtml xml:ns
http://www.w3.org/1998/Math/MathML.txt]
Result: {<html
xmlns="http://www.w3.org/1999/xhtml"="xml:ns"="http://www.w3.org/1998/Math/M
athML.txt">}
Correct: {<html xmlns="http://www.w3.org/1999/xhtml"
xml:ns="http://www.w3.org/1998/Math/MathML.txt">}
Test failed!
Input: [html xmlns http://www.w3.org/1999/xhtml/ xml:lang "en" lang
en
]
Result: {<html xmlns="http://www.w3.org/1999/xhtml/"="xml:lang"="en"
lang="en">}
Correct: {<html xmlns="http://www.w3.org/1999/xhtml/" xml:lang="en"
lang="en">}
Here's a replacement 'build-tag:
Build-Tag: function [
"Generates a tag from a composed block."
Values [block!] "Block of parens to evaluate and other data."
] [
Tag Value_Rule XML? Name Attribute Value
] [
Tag: make string! 7 * length? Values
Value_Rule: [
set Value issue! (Value: mold Value)
| set Value file! (Value: replace/all copy Value #" " " ")
| set Value any-type!
]
XML?: false
parse compose Values [
[
set Name ['?xml (XML?: true) | word!] (
append Tag Name
)
any [
set Attribute [word! | url!] Value_Rule (
Tag: rejoin [
Tag #" " Attribute {="} Value {"}
]
)
| Value_Rule (
Tag: reform [Tag Value]
)
]
end (
if XML? [
append Tag #"?"
]
)
]
| [
set Name refinement! any any-type! end (
Tag: mold Name
)
]
]
to tag! Tag
]
And here's some test software to check out the differences:
Test: :Build-Tag
Tests: [
[input "checked" type "radio" name "Favourite" value "cat"]
<input checked type="radio" name="Favourite" value="cat">
[html xml:lang "en"]
<html xml:lang="en">
[body text #FF80CC]
<body text="#FF80CC">
[a href %"Test File Space.txt"]
<a href="Test File Space.txt">
[/html gibber %Froth.txt]
</html>
[/html]
</html>
[?xml version "1.0" encoding "UTF-8"]
<?xml version="1.0" encoding="UTF-8"?>
[html xmlns http://www.w3.org/1999/xhtml xml:lang "en" lang "en"]
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
[html xmlns http://www.w3.org/1999/xhtml xml:ns
http://www.w3.org/1998/Math/MathML.txt]
<html xmlns="http://www.w3.org/1999/xhtml"
xml:ns="http://www.w3.org/1998/Math/MathML.txt">
[a href http://www.w3.org/TR/xhtml11/DTD/xhtml11-frameset.dtd]
<a href="http://www.w3.org/TR/xhtml11/DTD/xhtml11-frameset.dtd">
[html xmlns http://www.w3.org/1999/xhtml/ xml:lang "en" lang "en"]
<html xmlns="http://www.w3.org/1999/xhtml/" xml:lang="en" lang="en">
]
foreach [Input Correct] Tests [
Result: mold Test Input
Correct: mold Correct
if not all [
found? find/case Result Correct
found? find/case Correct Result
] [
print rejoin [
"Test failed!" newline
"Input: " tab mold Input newline
"Result: " tab mold Result newline
"Correct:" tab mold Correct
]
]
]
Watch out for line breaks!
I've also sent this to [feedback--rebol--com].
Andrew Martin
ICQ: 26227169 http://valley.150m.com/