Commit Graph

31 Commits

Author SHA1 Message Date
Raymond Zhou
48e44edfd0 Pass HTML responses as plain-text in rails-ujs
Running HTML responses through `DOMParser#parseFromString` results in
complete `HTMLDocument` instances with unnecessary surrounding tags.

For example:

    new DOMParser().parseFromString('<p>hello</p>', 'text/html')

Will output:

    <html>
      <head></head>
      <body>
        <p>hello</p>
      </body>
    </html>

This is passed to the `ajax:success` handler as `event.detail[0]`
(`data`), but cannot be used directly without first traversing the
document.

To resolve this, only XML content is passed through `parseFromString`,
while HTML content is treated as plain-text.

This matches the behavior of jquery-ujs, which relied on jQuery's
response-type inference.
2018-03-19 03:24:56 -04:00
Andrew White
31abee0341 Add support for automatic nonce generation for Rails UJS
Because the UJS library creates a script tag to process responses it
normally requires the script-src attribute of the content security
policy to include 'unsafe-inline'.

To work around this we generate a per-request nonce value that is
embedded in a meta tag in a similar fashion to how CSRF protection
embeds its token in a meta tag. The UJS library can then read the
nonce value and set it on the dynamically generated script tag to
enable it to execute without needing 'unsafe-inline' enabled.

Nonce generation isn't 100% safe - if your script tag is including
user generated content in someway then it may be possible to exploit
an XSS vulnerability which can take advantage of the nonce. It is
however an improvement on a blanket permission for inline scripts.

It is also possible to use the nonce within your own script tags by
using `nonce: true` to set the nonce value on the tag, e.g

    <%= javascript_tag nonce: true do %>
      alert('Hello, World!');
    <% end %>

Fixes #31689.
2018-02-19 15:59:34 +00:00
Mike Fiedler
0ae2476acd
Update rails-ujs readme
Link to W3C reference was broken, this uses the latest URL, along with HTTPS.
2018-01-29 19:18:35 -05:00
Javan Makhmali
48de6e9bda Revert unintentional change in 41e3bbd 2018-01-01 13:24:51 -05:00
Javan Makhmali
41e3bbdee1 Improve preventDefault fix for rails-ujs
Improves 049a3374aa85f33091f0e7cba8635edd4b4786bd:

* Attempt native `preventDefault()` before stepping in
* Fix that calling `preventDefault()` more than once would throw an error
* Fix that non-cancelable events could be canceled
2018-01-01 13:02:07 -05:00
Yoshiyuki Hirano
b20354afcc Bump license years for 2018 2017-12-31 22:36:55 +09:00
Yuri S
049a3374aa
Fix IE 10 and IE 11's broken preventDefault
https://github.com/turbolinks/turbolinks/issues/233
https://stackoverflow.com/questions/23349191/event-preventdefault-is-not-working-in-ie-11-for-custom-events
2017-12-27 18:39:44 +05:00
ta1kt0me
8b22725c78 Enable to call Rails.ajax without beforeSend 2017-10-28 12:13:19 +09:00
Akira Matsuda
731ea4e3fb Merge pull request #30513 from y-yagi/fix_30444
Does not include disabled element in params
2017-10-25 21:10:37 +09:00
Guillermo Iguaran
13132d8c32 Merge pull request #29710 from padi/rails-ujs-docs
Adds descriptions to rails-ujs methods [ci skip]
2017-10-22 07:55:44 -05:00
Guillermo Iguaran
b7bf709823 Merge pull request #29127 from DmytroVasin/rails-ujs-remote-callbacks
Fix callback in rails ujs
2017-10-19 09:13:31 -05:00
Elliot Winkler
f01f2e648d rails-ujs: Update README
Make various wording tweaks to cater to users who are viewing the README
on NPM. Notably, don't highlight Yarn specifically in the installation
instructions -- even though this is the preferred tool of choice
especially in the Ruby community, some people still use NPM (and,
really, ES2015+ syntax has nothing to do with NPM or Yarn).
2017-10-02 16:51:59 -05:00
yuuji.yaginuma
a5d80d4a1c Does not include disabled element in params
In the case of remote, it should be the same behavior as submitting
HTML form.

Fixes #30444
2017-09-03 17:02:38 +09:00
Marc Rendl Ignacio
ff4b18358d Adds descriptions to rails-ujs methods [ci skip] 2017-07-07 15:34:35 +08:00
Vasin Dmitriy
19afeaf580 Fix callback in rails ujs 2017-06-07 08:33:33 +03:00
Jon Moss
48f2a0c566 Grammar fixes
[ci skip]
2017-05-29 19:33:44 -04:00
Guillermo Iguaran
cbf378bc27 Merge pull request #29151 from onemanstartup/jquery_slim_fix
Check for jQuery ajax
2017-05-29 13:37:53 -05:00
Kasper Timm Hansen
41c040ad25 Merge pull request #29108 from inopinatus/ujs-sgjs-ie9-support
Fix server-generated JS response processing on IE9
2017-05-28 17:15:48 +02:00
Adrian Stainforth
b8d0a08832
Update to rails-ujs documentation for yarn install 2017-05-26 18:34:24 -04:00
Josef Šimánek
b0a258fa21 Update test link in ActionView javascripts README.md.
[ci skip]
2017-05-22 09:57:00 +02:00
Dmitriy Plekhanov
f1a740ef3c Check for jQuery ajax
jQuery slim version doesn't have ajax, so if a person include this version ajaxFilter raises error.
2017-05-19 22:42:02 +03:00
Josh Goodall
4be50a4a45 Fix server-generated JS response processing on IE9 when using rails-ujs and remote: true 2017-05-17 08:40:54 +10:00
Dmytro Vasin
db65f73f2e Fix mistake in JS response parser:
-
  Restore ability to accept ecmascript
  JS response should not modify DOM.
2017-04-13 16:58:36 +03:00
Dmytro Vasin
dc8ddea563 Set current page as default for ajax requests 2017-04-11 06:56:52 +03:00
Javan Makhmali
11341fdb3a Reorganize rails-ujs files 2017-03-30 14:41:17 -04:00
Ryunosuke Sato
40f226ae94 Fix link to rails-ujs
https://github.com/rails/rails-ujs is merged into actionview in favor of https://github.com/rails/rails/pull/28098.
[skip ci]
2017-03-30 01:10:20 +09:00
Patrick Toomey
9ca712348e
Prevent event propogation if element is disabled when event chain begins.
The existing UJS event behavior relies on browsers not sending events for
various events when an element is disabled. For example, imagine the following:

    <button type="submit" disabled="disabled">Click me</button>

The above button is disabled, so browsers will not trigger a click event and
all UJS behavior is prevented. However, imagine a button like this:

    <button type="submit" disabled="disabled"><strong>Click me</strong></button>

The above is treated differently by browsers such as Chrome/Safari. These
browsers do not consider the strong tag to be disabled, and will trigger click
events. UJS has logic to walk up the DOM to find an associated element subject
to UJS behavior. But, this logic does not take into account the disabled
status of the element.

I originally thought we could simply change the selectors used to match
elements to ignore disabled elements. However, UJS disables some elements as
part of the event chain. So, an element might match early in the chain and
then fail to match later. Instead of changing the selectors I added a callback
to the chain that calls `stopEverything` if an element is disabled when the
event chain begins.
2017-03-09 23:06:18 -07:00
Rafael Mendonça França
f24c2f09f8
Move rails-ujs README and LICENCE to actionview
We are going to make rails/rails the official repository
2017-02-22 13:49:27 -05:00
Guillermo Iguaran
41c33bd4b2 Import rails-ujs v0.1.0 from rails/rails-ujs 2017-02-20 14:29:55 +09:00
Akira Matsuda
650e46afbc s/an/a/
[ci skip]
2017-01-26 00:56:40 +09:00
Guillermo Iguaran
ad3a47759e Add rails-ujs to Action View 2016-11-26 01:23:07 -05:00