aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee
diff options
context:
space:
mode:
authorRaymond Zhou <razh@users.noreply.github.com>2018-03-19 02:42:23 -0400
committerrazh <somecrazyidiot@gmail.com>2018-03-19 03:24:56 -0400
commit48e44edfd0a8a7a29aa8fad39638ac0ee5243f42 (patch)
tree1ae9709f5dd11b7fa10f9bf12dfe950dc8fa6e39 /actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee
parentd91e6f1213146e327b47f2a65776c7f4f347a2d6 (diff)
downloadrails-48e44edfd0a8a7a29aa8fad39638ac0ee5243f42.tar.gz
rails-48e44edfd0a8a7a29aa8fad39638ac0ee5243f42.tar.bz2
rails-48e44edfd0a8a7a29aa8fad39638ac0ee5243f42.zip
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.
Diffstat (limited to 'actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee')
-rw-r--r--actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee2
1 files changed, 1 insertions, 1 deletions
diff --git a/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee b/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee
index 2a8f5659e3..cf31c796df 100644
--- a/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee
+++ b/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee
@@ -69,7 +69,7 @@ processResponse = (response, type) ->
script.nonce = cspNonce()
script.text = response
document.head.appendChild(script).parentNode.removeChild(script)
- else if type.match(/\b(xml|html|svg)\b/)
+ else if type.match(/\bxml\b/)
parser = new DOMParser()
type = type.replace(/;.+/, '') # remove something like ';charset=utf-8'
try response = parser.parseFromString(response, type)