[Pkg-javascript-commits] [dojo] 93/149: Fix dojo.hash() when there's a <base> tag. Patch from Rob Retchless (IBM, CCLA) with some modifications by me. Fixes #11100.

David Prévot taffit at moszumanska.debian.org
Sat Feb 27 03:13:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository dojo.

commit 58ed8621b7f1c5bb923f0f7172448738c31df904
Author: Bill Keese <bill at dojotoolkit.org>
Date:   Fri Oct 9 19:27:01 2015 +0900

    Fix dojo.hash() when there's a <base> tag.
    Patch from Rob Retchless (IBM, CCLA) with some modifications by me.
    Fixes #11100.
---
 hash.js                             |  5 +++--
 tests/functional/all.js             |  1 +
 tests/functional/hash.js            |  3 +++
 tests/functional/hash/basehref.html | 24 ++++++++++++++++++++++++
 tests/functional/hash/basehref.js   | 23 +++++++++++++++++++++++
 5 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/hash.js b/hash.js
index 2787a7a..6427119 100644
--- a/hash.js
+++ b/hash.js
@@ -38,7 +38,7 @@ define(["./_base/kernel", "require", "./_base/config", "./aspect", "./_base/lang
 		if(replace){
 			_replace(hash);
 		}else{
-			location.href = "#" + hash;
+			location.hash = "#" + hash;
 		}
 		return hash; // String
 	};
@@ -81,7 +81,8 @@ define(["./_base/kernel", "require", "./_base/config", "./aspect", "./_base/lang
 			_ieUriMonitor.iframe.location.replace(href.substring(0, index) + "?" + hash);
 			return;
 		}
-		location.replace("#"+hash);
+		var href = location.href.replace(/#.*/, "");
+		location.replace(href + "#" + hash);
 		!_connect && _pollLocation();
 	}
 
diff --git a/tests/functional/all.js b/tests/functional/all.js
index 3a56e27..96d94be 100644
--- a/tests/functional/all.js
+++ b/tests/functional/all.js
@@ -8,6 +8,7 @@ define([
 	'./dnd',
 	'./fx',
 	'./fx/Toggler',
+	'./hash',
 	'./io/script',
 	'./on',
 	'./parser',
diff --git a/tests/functional/hash.js b/tests/functional/hash.js
new file mode 100644
index 0000000..37029f9
--- /dev/null
+++ b/tests/functional/hash.js
@@ -0,0 +1,3 @@
+define([
+	'./hash/basehref'
+], function () { });
diff --git a/tests/functional/hash/basehref.html b/tests/functional/hash/basehref.html
new file mode 100644
index 0000000..e28a6d1
--- /dev/null
+++ b/tests/functional/hash/basehref.html
@@ -0,0 +1,24 @@
+<html>
+<head>
+	<title>dojo.hash() with <base> test</title>
+	<script>
+		var ready = false;
+	</script>
+	<script type="text/javascript" src="../../../dojo.js" ></script>
+	<script>dojo.require('dojo.hash');</script>
+	<base href="http://dojotoolkit.org/">
+	<script>
+		dojo.ready(function(){
+			ready = true;
+		});
+	</script>
+</head>
+<body>
+	<h1>dojo.hash() with <base> test</h1>
+	<p id="_location"></p>
+	<div style="padding: 20px">
+		<button id='sethash' onclick="dojo.hash('#myhash1')">dojo.hash('#myhash1')</button>
+		<button id='sethashtrue' onclick="dojo.hash('#myhash2', true)">dojo.hash('#myhash2', true)</button>
+	</div>
+</body>
+</html>
diff --git a/tests/functional/hash/basehref.js b/tests/functional/hash/basehref.js
new file mode 100644
index 0000000..30b3985
--- /dev/null
+++ b/tests/functional/hash/basehref.js
@@ -0,0 +1,23 @@
+define([
+	'require',
+	'intern!object',
+	'intern/chai!assert',
+	'../../support/ready'
+], function (require, registerSuite, assert, ready) {
+	registerSuite({
+		name: 'dojo/hash',
+
+		sethash: function () {
+			return ready(this.get('remote'), require.toUrl('./basehref.html'))
+				.findById('sethash').click().end()
+				.execute('return window.location.href').then(function(url){
+					assert.isTrue(/basehref\.html#myhash1$/.test(url), 'setHash("myhash1"), location.href: ' + url);
+				})
+				.findById('sethashtrue').click().end()
+				.execute('return window.location.href').then(function(url){
+					assert.isTrue(/basehref\.html#myhash2$/.test(url),
+						'setHash("myhash1", true), location.href: ' + url);
+				})
+		}
+	});
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list