Permalink
Browse files

fix to allow nested tags written in shorthand to be resolved to the c…

…orrect name
  • Loading branch information...
1 parent 8ec6fb9 commit e14b455bde9a04a0fd4052291071b6c36cb553b2 @jlong jlong committed Mar 21, 2006
Showing with 29 additions and 20 deletions.
  1. +15 −3 radius/lib/radius.rb
  2. +14 −17 radius/test/radius_test.rb
View
@@ -354,13 +354,25 @@ def stack(name, attributes, block)
# Returns a fully qualified tag name based on state of the
# tag binding stack.
def qualified_tag_name(name)
+ n = name
+ loop do
+ tag_name = scan_stack_for_tag_name(n)
+ return tag_name if tag_name
+ break unless n =~ /^(.*?):(.*)$/
+ n = $2
+ end
+ name
+ end
+
+ def scan_stack_for_tag_name(name)
names = @tag_binding_stack.collect { |tag| tag.name }
- while names.size > 0
+ loop do
try = (names + [name]).join(':')
- return try if @definitions.has_key? try
+ return try if @definitions.has_key? try
names.pop
+ break unless names.size > 0
end
- name
+ nil
end
end
@@ -132,25 +132,22 @@ def test_parse_double_tags
assert_parse_output "tset TEST", "<r:reverse>test</r:reverse> <r:capitalize>test</r:capitalize>"
end
- def test_parse_nested
- define_tag("outer") { |tag| tag.expand.reverse }
- define_tag("outer:inner") { |tag| ["renni", tag.expand].join }
- define_tag("outer:inner:heart") { "heart" }
- define_tag("outer:branch") { "branch" }
- assert_parse_output "inner", "<r:outer><r:inner /></r:outer>"
- assert_parse_output "renni", "<r:outer:inner />"
- assert_parse_output "heart", "<r:outer:inner:heart />"
- assert_parse_output "hcnarbinner", "<r:outer><r:inner><r:branch /></r:inner></r:outer>"
- assert_raises(Radius::UndefinedTagError) { @parser.parse("<r:inner />") }
- end
-
- def test_nesting
- define_tag("outer", :for => '')
- define_tag("outer:inner", :for => '')
+ def test_parse_nesting
+ define_tag("parent", :for => '')
+ define_tag("parent:child", :for => '')
+ define_tag("extra", :for => '')
define_tag("nesting") { |tag| tag.nesting }
+ define_tag("extra:nesting") { |tag| tag.nesting.gsub(':', ' > ') }
+ define_tag("parent:child:nesting") { |tag| tag.nesting.gsub(':', ' * ') }
assert_parse_output "nesting", "<r:nesting />"
- assert_parse_output "outer:nesting", "<r:outer><r:nesting /></r:outer>"
- assert_parse_output "outer:inner:nesting", "<r:outer><r:inner><r:nesting /></r:inner></r:outer>"
+ assert_parse_output "parent:nesting", "<r:parent:nesting />"
+ assert_parse_output "extra > nesting", "<r:extra:nesting />"
+ assert_parse_output "parent * child * nesting", "<r:parent:child:nesting />"
+ assert_parse_output "parent > extra > nesting", "<r:parent:extra:nesting />"
+ assert_parse_output "parent > child > extra > nesting", "<r:parent:child:extra:nesting />"
+ assert_parse_output "parent:extra:child:nesting", "<r:parent:extra:child:nesting />"
+ assert_parse_output "extra * parent * child * nesting", "<r:extra:parent:child:nesting />"
+ assert_raises(Radius::UndefinedTagError) { @parser.parse("<r:child />") }
end
def test_parse_loops

0 comments on commit e14b455

Please sign in to comment.