Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Prevent recursion via the <r:content /> tag.
  • Loading branch information
seancribbs committed Jun 7, 2009
1 parent d7539d3 commit 815b49d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,8 @@

=== Edge

* Prevent recursion via the <r:content /> tag. [Sean Cribbs]
* Update Highline. [Sean Cribbs]
* Update Cucumber and RSpec, clean up some features and fix specs. [Sean Cribbs]
* Set the protected attributes for users in User.protected_attributes
[Jim Gay]
Expand Down
7 changes: 7 additions & 0 deletions app/models/standard_tags.rb
Expand Up @@ -347,6 +347,13 @@ class TagError < StandardError; end
tag 'content' do |tag|
page = tag.locals.page
part_name = tag_part_name(tag)
# Prevent simple and deep recursive rendering of the same page part

This comment has been minimized.

Copy link
@geapi

geapi Jun 3, 2010

Was this causing problems? I can see several useful situations where I want something rendered twice on the same page, for example a link as header and then underneath an article.

This comment has been minimized.

Copy link
@geapi

geapi Jun 4, 2010

that is odd, because exactly what you're describing gives me a recursion error :"Recursion error: already rendering the 'link' part"
or from your example 'a' part

This comment has been minimized.

Copy link
@joshfrench

joshfrench Jun 4, 2010

Member

geapi, check your closing tags.
Incorrect: <r:content part="a"><r:content part="a"/>/r:content
Correct: <r:content part="a"/><r:content part="a"/>

This comment has been minimized.

Copy link
@geapi

geapi Jun 4, 2010

odd, radiant 0.8.1 gives me the error, check http://bikeloc.org in the left column
the title of those posts and the read-on use the same content part (to generate the link) and on the "read-on"
I get the recursion error, the code I use to produce it is:
for the title:


<r:if_content part="link">
<a href="<r:content part="link"/>"><r:title />
/r:if_content
<r:unless_content part="link">
<r:title />
/r:unless_content


for the "read-on"

<r:if_content part="link">
<a href="<r:content part="link"/>">Read On
/r:if_content
<r:unless_content part="link">
Read On
/r:unless_content

This comment has been minimized.

Copy link
@saturnflyer

saturnflyer Jun 4, 2010

Member

I don't want to push out an 0.8.3 version, but if anyone wants to create a monkey-patch extension for this to override the standard_tags.rb we can put it into the main Radiant account.

rendered_parts = (tag.locals.rendered_parts ||= Hash.new {|h,k| h[k] = []})
if rendered_parts[page.id].include?(part_name)
raise TagError.new(%{Recursion error: already rendering the `#{part_name}' part.})
else
rendered_parts[page.id] << part_name
end
boolean_attr = proc do |attribute_name, default|
attribute = (tag.attr[attribute_name] || default).to_s
raise TagError.new(%{`#{attribute_name}' attribute of `content' tag must be set to either "true" or "false"}) unless attribute =~ /true|false/i
Expand Down
5 changes: 5 additions & 0 deletions spec/datasets/pages_dataset.rb
Expand Up @@ -51,6 +51,11 @@ def load
create_page_part "games"
create_page "Guests"
end
create_page "Recursive parts" do
create_page_part "recursive_body", :name => "body", :content => "<r:content />"
create_page_part "recursive_one", :name => "one", :content => '<r:content part="two" />'
create_page_part "recursive_two", :name => "two", :content => '<r:content part="one" />'
end
end

end
9 changes: 9 additions & 0 deletions spec/models/standard_tags_spec.rb
Expand Up @@ -253,6 +253,15 @@
page(:home).should render('<r:content part="extended" />').as("Just a test.")
end

it "should prevent simple recursion" do
page(:recursive_parts).should render('<r:content />').with_error("Recursion error: already rendering the `body' part.")
end

it "should prevent deep recursion" do
page(:recursive_parts).should render('<r:content part="one"/>').with_error("Recursion error: already rendering the `one' part.")
page(:recursive_parts).should render('<r:content part="two"/>').with_error("Recursion error: already rendering the `two' part.")
end

describe "with inherit attribute" do
it "missing or set to 'false' should render the current page's part" do
page.should render('<r:content part="sidebar" />').as('')
Expand Down

0 comments on commit 815b49d

Please sign in to comment.