Skip to content

Commit

Permalink
Don't escape CDATA text...
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jul 5, 2024
1 parent eaf725b commit 617a8ee
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/utopia/content/markup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def instruction(string)
end

def cdata(string)
@delegate.text(string[9..-4])
@delegate.write(string[9..-4])
end

def text(string)
Expand Down
3 changes: 3 additions & 0 deletions test/utopia/.content/script/cdata.xnode
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script type="text/javascript"><![CDATA[
console.log("Hello World!");
]]></script>
8 changes: 8 additions & 0 deletions test/utopia/.content/script/importmap.xnode
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script type="importmap">
{
"imports": {
"test": "/_assets/test.js",
"test2": "/_assets/test2.js"
}
}
</script>
26 changes: 26 additions & 0 deletions test/utopia/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@
expect(last_response.body).to be == '10'
end

it "should generate valid importmap" do
get "/script/importmap"

expect(last_response.body).to be == <<~IMPORTMAP.chomp
<script type="importmap">
{
"imports": {
"test": "/_assets/test.js",
"test2": "/_assets/test2.js"
}
}
</script>
IMPORTMAP
end

it "should generate valid javascript" do
get "/script/cdata"

# We are expected to generate HTML... there is no good convention for "escaping javascript" in HTML. So we just plonk it in, verbatim. Yay.
expect(last_response.body).to be == <<~JAVASCRIPT.chomp
<script type="text/javascript">
console.log("Hello World!");
</script>
JAVASCRIPT
end

it "should successfully redirect to the foo page" do
get '/content/redirect'

Expand Down
2 changes: 1 addition & 1 deletion test/utopia/content/markup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def parse(string)
[:tag_begin, foo_tag],
[:text, "Bob & Barley"],
[:write, "<!-- Comment -->"],
[:text, "Hello & World"],
[:write, "Hello & World"],
[:tag_end, foo_tag],
]

Expand Down

0 comments on commit 617a8ee

Please sign in to comment.