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

Fix partial rendering with dot in filename #24052

Conversation

bquorning
Copy link
Contributor

When rendering a collection with a partial whose filename contains a dot, e.g. "customer.mobile", we would set a locals[:'customer.mobile'] variable instead of, as in earlier versions of Rails, locals[:customer].

This bug was introduced in da9038e.

When rendering a collection with a partial whose filename contains a dot, e.g.
"customer.mobile", we would set a `locals[:'customer.mobile']` variable instead
of, as in earlier versions of Rails, `locals[:customer]`.

This bug was introduced in da9038e.
@rails-bot
Copy link

r? @schneems

(@rails-bot has picked a reviewer for you, use r? to override)

@schneems
Copy link
Member

schneems commented Mar 4, 2016

Do you know why or when this behavior changed?

@bquorning
Copy link
Contributor Author

Hey @schneems. This bug was introduced in da9038e.

@schneems
Copy link
Member

schneems commented Mar 4, 2016

@amatsuda can you take a look at this PR?

@amatsuda amatsuda assigned amatsuda and unassigned schneems Mar 4, 2016
@amatsuda
Copy link
Member

amatsuda commented Mar 4, 2016

@bquorning Interesting. I've never seen such a code, and it's actually an untested (=undefined) behavior so far, but there's no reason not to keep the compatibility on your code.
Thank you for the fix! ❤️

amatsuda added a commit that referenced this pull request Mar 4, 2016
…ction-and-dot-in-partial-name

Fix partial rendering with dot in filename
@amatsuda amatsuda merged commit c577657 into rails:master Mar 4, 2016
@bquorning bquorning deleted the partial-rendering-with-collection-and-dot-in-partial-name branch March 4, 2016 14:31
@bquorning
Copy link
Contributor Author

Thank you for the merge.

@@ -521,7 +521,7 @@ def retrieve_template_keys
def retrieve_variable(path, as)
variable = as || begin
base = path[-1] == "/".freeze ? "".freeze : File.basename(path)
raise_invalid_identifier(path) unless base =~ /\A_?(.*)(?:\.\w+)*\z/
raise_invalid_identifier(path) unless base =~ /\A_?(.*?)(\.\w+)*\z/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry. I just now noticed that there’s really no need to remove ?: from the last regex capture.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I added the ?: to express that we're only using $1 afterwards.
It would work without ?:, or you can make another PR adding ?:, or I would just push these 2 chars.
I'm fine with any option :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit directly to master – that’s probably the easiest option :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bquorning Done. 28a6571
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants