haml-edge 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/EDGE_GEM_VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.2
1
+ 2.3.3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.2
1
+ 2.3.3
@@ -204,13 +204,13 @@ END
204
204
  when ELEMENT; render_tag(text)
205
205
  when COMMENT; render_comment(text[1..-1].strip)
206
206
  when SANITIZE
207
- return push_script(unescape_interpolation(text[3..-1].strip), :escape_html => true) if text[1..2] == "=="
207
+ return push_plain(text[3..-1].strip, :escape_html => true) if text[1..2] == "=="
208
208
  return push_script(text[2..-1].strip, :escape_html => true) if text[1] == SCRIPT
209
- return push_script(unescape_interpolation(text[1..-1].strip), :escape_html => true) if text[1] == ?\s
209
+ return push_flat_script(text[2..-1].strip, :escape_html => true) if text[1] == FLAT_SCRIPT
210
+ return push_plain(text[1..-1].strip, :escape_html => true) if text[1] == ?\s
210
211
  push_plain text
211
212
  when SCRIPT
212
- return push_script(unescape_interpolation(text[2..-1].strip)) if text[1] == SCRIPT
213
- return push_script(text[1..-1], :escape_html => true) if options[:escape_html]
213
+ return push_plain(text[2..-1].strip) if text[1] == SCRIPT
214
214
  push_script(text[1..-1])
215
215
  when FLAT_SCRIPT; push_flat_script(text[1..-1])
216
216
  when SILENT_SCRIPT
@@ -237,9 +237,10 @@ END
237
237
  when FILTER; start_filtered(text[1..-1].downcase)
238
238
  when DOCTYPE
239
239
  return render_doctype(text) if text[0...3] == '!!!'
240
- return push_script(unescape_interpolation(text[3..-1].strip)) if text[1..2] == "=="
241
- return push_script(text[2..-1].strip) if text[1] == SCRIPT
242
- return push_script(unescape_interpolation(text[1..-1].strip)) if text[1] == ?\s
240
+ return push_plain(text[3..-1].strip, :escape_html => false) if text[1..2] == "=="
241
+ return push_script(text[2..-1].strip, :escape_html => false) if text[1] == SCRIPT
242
+ return push_flat_script(text[2..-1].strip, :escape_html => false) if text[1] == FLAT_SCRIPT
243
+ return push_plain(text[1..-1].strip, :escape_html => false) if text[1] == ?\s
243
244
  push_plain text
244
245
  when ESCAPE; push_plain text[1..-1]
245
246
  else push_plain text
@@ -306,13 +307,13 @@ END
306
307
 
307
308
  # Renders a block of text as plain text.
308
309
  # Also checks for an illegally opened block.
309
- def push_plain(text)
310
+ def push_plain(text, options = {})
310
311
  if block_opened?
311
312
  raise SyntaxError.new("Illegal nesting: nesting within plain text is illegal.", @next_line.index)
312
313
  end
313
314
 
314
315
  if contains_interpolation?(text)
315
- push_script unescape_interpolation(text)
316
+ push_script unescape_interpolation(text), :escape_html => options[:escape_html]
316
317
  else
317
318
  push_text text
318
319
  end
@@ -333,6 +334,7 @@ END
333
334
  def push_script(text, opts = {})
334
335
  raise SyntaxError.new("There's no Ruby code for = to evaluate.") if text.empty?
335
336
  return if options[:suppress_eval]
337
+ opts[:escape_html] = options[:escape_html] if opts[:escape_html].nil?
336
338
 
337
339
  args = %w[preserve_script in_tag preserve_tag escape_html nuke_inner_whitespace]
338
340
  args.map! {|name| opts[name.to_sym]}
@@ -363,11 +365,11 @@ END
363
365
 
364
366
  # Causes <tt>text</tt> to be evaluated, and Haml::Helpers#find_and_flatten
365
367
  # to be run on it afterwards.
366
- def push_flat_script(text)
368
+ def push_flat_script(text, options = {})
367
369
  flush_merged_text
368
370
 
369
371
  raise SyntaxError.new("There's no Ruby code for ~ to evaluate.") if text.empty?
370
- push_script(text, :preserve_script => true)
372
+ push_script(text, options.merge(:preserve_script => true))
371
373
  end
372
374
 
373
375
  def start_haml_comment
@@ -651,8 +653,9 @@ END
651
653
  parse = true
652
654
  value = unescape_interpolation(value[1..-1].strip) if value[0] == ?=
653
655
  when '&', '!'
654
- if value[0] == ?=
656
+ if value[0] == ?= || value[0] == ?~
655
657
  parse = true
658
+ preserve_script = (value[0] == ?~)
656
659
  value =
657
660
  if value[1] == ?=
658
661
  unescape_interpolation(value[2..-1].strip)
@@ -359,6 +359,68 @@ HTML
359
359
  HAML
360
360
  end
361
361
 
362
+ def test_escape_html
363
+ html = <<HTML
364
+ &amp;
365
+ &
366
+ &amp;
367
+ HTML
368
+
369
+ assert_equal(html, render(<<HAML, :escape_html => true))
370
+ &= "&"
371
+ != "&"
372
+ = "&"
373
+ HAML
374
+
375
+ assert_equal(html, render(<<HAML, :escape_html => true))
376
+ &~ "&"
377
+ !~ "&"
378
+ ~ "&"
379
+ HAML
380
+
381
+ assert_equal(html, render(<<HAML, :escape_html => true))
382
+ & \#{"&"}
383
+ ! \#{"&"}
384
+ \#{"&"}
385
+ HAML
386
+
387
+ assert_equal(html, render(<<HAML, :escape_html => true))
388
+ &== \#{"&"}
389
+ !== \#{"&"}
390
+ == \#{"&"}
391
+ HAML
392
+
393
+ tag_html = <<HTML
394
+ <p>&amp;</p>
395
+ <p>&</p>
396
+ <p>&amp;</p>
397
+ HTML
398
+
399
+ assert_equal(tag_html, render(<<HAML, :escape_html => true))
400
+ %p&= "&"
401
+ %p!= "&"
402
+ %p= "&"
403
+ HAML
404
+
405
+ assert_equal(tag_html, render(<<HAML, :escape_html => true))
406
+ %p&~ "&"
407
+ %p!~ "&"
408
+ %p~ "&"
409
+ HAML
410
+
411
+ assert_equal(tag_html, render(<<HAML, :escape_html => true))
412
+ %p& \#{"&"}
413
+ %p! \#{"&"}
414
+ %p \#{"&"}
415
+ HAML
416
+
417
+ assert_equal(tag_html, render(<<HAML, :escape_html => true))
418
+ %p&== \#{"&"}
419
+ %p!== \#{"&"}
420
+ %p== \#{"&"}
421
+ HAML
422
+ end
423
+
362
424
  # HTML escaping tests
363
425
 
364
426
  def test_ampersand_equals_should_escape
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml-edge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-07-09 00:00:00 -04:00
13
+ date: 2009-07-10 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency