diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2016-03-28 10:32:15 -0400 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2016-04-04 11:30:27 -0400 |
commit | 10fc59007d717432ea126e49ce4142e6c4d5136e (patch) | |
tree | 005e9d8de3d47001cf062f68f47709dd604284c4 /src/core/parseHTML.js | |
parent | 5cbb234dd3273d8e0bbd454fb431ad639c7242c1 (diff) | |
download | jquery-10fc59007d717432ea126e49ce4142e6c4d5136e.tar.gz jquery-10fc59007d717432ea126e49ce4142e6c4d5136e.zip |
Core: set the base href of the context in parseHTML
Fixes gh-2965
Close gh-3022
Diffstat (limited to 'src/core/parseHTML.js')
-rw-r--r-- | src/core/parseHTML.js | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/core/parseHTML.js b/src/core/parseHTML.js index 30405363c..260fd3ca7 100644 --- a/src/core/parseHTML.js +++ b/src/core/parseHTML.js @@ -21,14 +21,28 @@ jQuery.parseHTML = function( data, context, keepScripts ) { context = false; } - // Stop scripts or inline event handlers from being executed immediately - // by using document.implementation - context = context || ( support.createHTMLDocument ? - document.implementation.createHTMLDocument( "" ) : - document ); - - var parsed = rsingleTag.exec( data ), - scripts = !keepScripts && []; + var base, parsed, scripts; + + if ( !context ) { + + // Stop scripts or inline event handlers from being executed immediately + // by using document.implementation + if ( support.createHTMLDocument ) { + context = document.implementation.createHTMLDocument( "" ); + + // Set the base href for the created document + // so any parsed elements with URLs + // are based on the document's URL (gh-2965) + base = context.createElement( "base" ); + base.href = document.location.href; + context.head.appendChild( base ); + } else { + context = document; + } + } + + parsed = rsingleTag.exec( data ); + scripts = !keepScripts && []; // Single tag if ( parsed ) { |