Subject: | The plugin assumes that $ is aliased to jquery. That is not always the case. |
Date: | Tue, 25 Sep 2012 00:40:28 -0400 |
To: | bug-Mojolicious-Plugin-CSRFProtect [...] rt.cpan.org |
From: | "Gillen, Martin" <martin_gillen [...] mitel.com> |
The user may have used the
jQuery.noConflict()<http://api.jquery.com/jQuery.noConflict/>method to
alias a different variable to jQuery like:
<script type="text/javascript">
var j = jQuery.noConflict()
</script>
In this case, the plugin will not work.
I have written a small patch (also attached) which fixes this issue (based
on version 0.10):
---------------------------------------------------------------------------------------------------------------------------
--- CSRFProtect.pm 2012-09-25 00:23:54.930207000 -0400
+++ CSRFProtect.pm.updated 2012-09-25 00:24:13.041003000 -0400
@@ -46,10 +46,11 @@
# Add "jquery_ajax_csrf_protection" helper
$app->helper(
jquery_ajax_csrf_protection => sub {
+ my $jq = $_[1] | '$';
my $js = '<meta name="csrftoken" content="' .
$self->_csrftoken( $_[0] ) . '"/>';
$js .= q!<script type="text/javascript">!;
- $js .= q! $(document).ajaxSend(function(e, xhr, options) { !;
- $js .= q! var token =
$("meta[name='csrftoken']").attr("content");!;
+ $js .= q! !.$jq.q!(document).ajaxSend(function(e, xhr,
options) { !;
+ $js .= q! var token =
!.$jq.q!("meta[name='csrftoken']").attr("content");!;
$js .= q! xhr.setRequestHeader("X-CSRF-Token", token);!;
$js .= q! });</script>!;
@@ -180,6 +181,14 @@
You should add <%= jquery_ajax_csrf_protection %> in head of your HTML
page.
+ If you have created an alternative alias for jQuery using
jQuery.noConflict, you can pass it as an argument:
+
+ <script type="text/javascript">
+ var j = jQuery.noConflict()
+ </script>
+
+ <%= jquery_ajax_csrf_protection('j') %>
+
=head2 C<csrftoken>
returns CSRF Protection token.
---------------------------------------------------------------------------------------------------------------------------
Thanks,
*Martin A. Gillen*
*________________________
Desktop Extension 72331
Phase 4 Floor 4 Pillar J6*
--
This e-mail (including any attachments) is for the sole use of the intended
recipient(s) and may contain information that is confidential and/or
protected by legal privilege. Any unauthorized review, use, copy,
disclosure or distribution of this e-mail is strictly prohibited. If you
are not the intended recipient, please notify Mitel immediately and destroy
all copies of this e-mail. Mitel does not accept any liability for breach
of security, error or virus that may result from the transmission of this
message.
Message body is not shown because sender requested not to inline it.
Message body not shown because it is not plain text.