Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fragment_for assumes ActionView::OutputBuffer. #1787

Conversation

cmeiklejohn
Copy link
Contributor

Handle for cases where the buffer is a SafeBuffer, or a particular subclass of SafeBuffer.

If this looks good, I'll make a patch for the other release branches.

Thanks!

@josevalim
Copy link
Contributor

I believe removing the if branch completely leaving just the else branch would work fine.

@cmeiklejohn
Copy link
Contributor Author

That doesn't work, as it attempts to concat a safe and a non-safe buffer together.

@josevalim
Copy link
Contributor

Could you please provide a test with such changes? I think since the beginning it had no tests. So unless we are testing it, we will be shooting in the dark. Tks!

@cmeiklejohn
Copy link
Contributor Author

Jose,

I just made the syntax a bit more concise. The original changes were implemented to address failures in ./actionpack/test/controller/caching_test.rb. I think the coverage there is already comprehensive and this change serves just to clean up the syntax.

Let me know if there is some specific test case you'd like to see tested.

@josevalim
Copy link
Contributor

Ah ok, thanks for the explanation. But there is still an issue with your code. Being a SafeBuffer no longer means the string is html safe. You should probably check it using html_safe? .

@cmeiklejohn
Copy link
Contributor Author

The code in place now currents assumes the data is safe, so I don't believe that is a new change.

Is it safe to assume the data is HTML safe? It's slicing out the content-to-cache from the output_buffer, which is resulting in the output_buffer being marked as dirty, and then it's being concat'd back with the fragment, so would it be safe to assume that the only way non-safe content would be rendered would be if it was read in from the cache?

@josevalim
Copy link
Contributor

Exactly, the current code assumes the output buffer is always safe, which is true for 90%, but for the other 10%, we may potentially mark some dirty content as safe. We should probably check for html_safe? before slicing the buffer. And when it comes to the fragment, the dirty state is preserved on cached, so I assume we don't really need to change anything.

@cmeiklejohn
Copy link
Contributor Author

Good point, latest commit stores the safe status of the buffer, and only marks safe if it was safe to begin with.

@josevalim
Copy link
Contributor

Tks! The if clause could simply be if output_safe, no?

@cmeiklejohn
Copy link
Contributor Author

Good call.

Should I cherry pick this to 3-0-stable and 3-1-stable?

josevalim added a commit that referenced this pull request Jun 20, 2011
…st_for_subclasses_of_safe_buffer

fragment_for assumes ActionView::OutputBuffer.
@josevalim josevalim merged commit ac78ff7 into rails:master Jun 20, 2011
@josevalim
Copy link
Contributor

cherry picking + squashing would be great.

@cmeiklejohn
Copy link
Contributor Author

Created pulls #1791 and #1792.

josevalim added a commit that referenced this pull request Jun 20, 2011
Cherry pick of pull #1787 into 3-1-stable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants