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

[5.1] Fix for issue #10068 #10464

Closed
wants to merge 4 commits into from
Closed

[5.1] Fix for issue #10068 #10464

wants to merge 4 commits into from

Conversation

mcgrogan91
Copy link

This merge fixes the issue (#10068) by adding a blade-specific version of the e() htmlentities shortcut. If we are echoing content in a blade file, we should likely be escaping any '@' characters we are echoing, as that character has special meaning to the Blade Interpreter. This change adds a blade escape helper function that replaces '@' with '@' - the htmlentities version of the character when it is inside of blade echo tags.

There is likely a more Blade-centric way to do this, but as the issue has existed for a while now I figured I would at least submit a fairly straightforward fix for this.

@GrahamCampbell
Copy link
Member

Please squash to one commit.

@GrahamCampbell
Copy link
Member

Also, the email address you used on git needs adding to your GitHub so the commits get associated with you.

It's probably safer to assume e is a function that was defined before, and is not guaranteed to be the one we see above us in the code.

Fixing PSR

StyleCI fix

IDE put spaces there, and there shouldn't be any
@mcgrogan91
Copy link
Author

Alright, think I squashed it and linked my account correctly.

@rentalhost
Copy link
Contributor

Can you add tests that should fail without your fix?

@GrahamCampbell GrahamCampbell changed the title Fix for issue #10068 [5.1] Fix for issue #10068 Oct 3, 2015
@taylorotwell
Copy link
Member

I agree I would like to see a test or two that fails without the fix.

@mcgrogan91
Copy link
Author

I'm not sure where I would put an overall test for this fix, as my implementation changes the BladeCompiler. The full test won't show a fix until the Factory processes the compiled output and no longer sees '@parent'. I'm not sure where to write a single test that covers that process, so I wrote a couple tests for the various steps of it.

I'm open to any input on where to write a full test for this.

@vlakoff
Copy link
Contributor

vlakoff commented Oct 8, 2015

I think be() is too easily confusable with the verb "to be"… Also, this name might be wanted for something else in the future (or in user code)? How about blade_e() or e_blade()?

@vlakoff
Copy link
Contributor

vlakoff commented Oct 8, 2015

btw, to reduce verbosity, maybe it's time to replace <?php echo to <?=. The package itself requires PHP 5.5, and uses PHP 5.4 array notation, so…

@rentalhost
Copy link
Contributor

I think that be() should not exists, but a static function can be created to do that service. Except if be() can be useful directly to user like e() does.

@vlakoff I think that use full php tag is better. Else, should be need replace it in all Laravel.

@vlakoff
Copy link
Contributor

vlakoff commented Oct 8, 2015

  • No opinion about helper vs. static method, haven't looked into it enough.
  • Searched for <?php echo in laravel/framework codebase. Only BladeCompiler.php and a few test fixtures contain it.

@taylorotwell
Copy link
Member

Yeah I wouldn't call this be I would also suggest making a static method. This isn't really a user-land function we want to make available globally.

@mcgrogan91
Copy link
Author

I like pulling it out into the static function rather than have it be user land global. It makes more sense here, since it's specific functionality related to an internal tool. Thanks for the PR, @rentalhost! I can squash these down again if this is a solution that might be accepted.

@rkgrep
Copy link

rkgrep commented Oct 15, 2015

Shouldn't this be implemented in 5.2?
It may break existing apps that are expecting raw @ in views. For instance, in mailto links.

@GrahamCampbell
Copy link
Member

I agree this belongs on 5.2, if at all.

@rentalhost
Copy link
Contributor

mailto shouldn't be affected, is very important to test it.
I think that it it is happening, should be avoided, instead of just wait to implement it on 5.2, because it acts like a bug (as in #10068).

@rkgrep
Copy link

rkgrep commented Oct 15, 2015

mailto is just an example. It may be some JS code that depends on @ symbol either.

@rentalhost
Copy link
Contributor

Exactly. In this case, I suggests make more tests avoiding 'hacks'. Maybe it causes more problem that solve others.

@GrahamCampbell
Copy link
Member

👎 for ths.

@GrahamCampbell
Copy link
Member

We need to just fix the actual issue instead of a workaround that's a bit dodgie.

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.

6 participants