aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMorris Jobke <morris.jobke@gmail.com>2014-01-29 00:39:14 -0800
committerMorris Jobke <morris.jobke@gmail.com>2014-01-29 00:39:14 -0800
commitcf2c061f1f2577b3a995d9e2423c93589d7df2b3 (patch)
tree43cf27eac956eff737b2a5edfcab429c811e403e /core
parent75c8d74c945293a65f0009caeb5a1ba33f21e37b (diff)
parentc6695bbd764be9f43067c09894e36422c2b92b49 (diff)
downloadnextcloud-server-cf2c061f1f2577b3a995d9e2423c93589d7df2b3.tar.gz
nextcloud-server-cf2c061f1f2577b3a995d9e2423c93589d7df2b3.zip
Merge pull request #6929 from owncloud/sharing-fixfiledownloadlink
Sharing fixfiledownloadlink
Diffstat (limited to 'core')
-rw-r--r--core/js/js.js34
-rw-r--r--core/js/tests/specs/coreSpec.js37
2 files changed, 71 insertions, 0 deletions
diff --git a/core/js/js.js b/core/js/js.js
index e84f482d672..1c7d89ea055 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -253,6 +253,12 @@ var OC={
return link;
},
/**
+ * Redirect to the target URL, can also be used for downloads.
+ */
+ redirect: function(targetUrl) {
+ window.location = targetUrl;
+ },
+ /**
* get the absolute path to an image file
* @param app the app id to which the image belongs
* @param file the name of the image file
@@ -364,6 +370,34 @@ var OC={
}
return result;
},
+
+ /**
+ * Builds a URL query from a JS map.
+ * @param params parameter map
+ * @return string containing a URL query (without question) mark
+ */
+ buildQueryString: function(params) {
+ var s = '';
+ var first = true;
+ if (!params) {
+ return s;
+ }
+ for (var key in params) {
+ var value = params[key];
+ if (first) {
+ first = false;
+ }
+ else {
+ s += '&';
+ }
+ s += encodeURIComponent(key);
+ if (value !== null && typeof(value) !== 'undefined') {
+ s += '=' + encodeURIComponent(value);
+ }
+ }
+ return s;
+ },
+
/**
* Opens a popup with the setting for an app.
* @param appid String. The ID of the app e.g. 'calendar', 'contacts' or 'files'.
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js
index 827669f270b..28c20a0642e 100644
--- a/core/js/tests/specs/coreSpec.js
+++ b/core/js/tests/specs/coreSpec.js
@@ -67,4 +67,41 @@ describe('Core base tests', function() {
});
});
});
+ describe('Query string building', function() {
+ it('Returns empty string when empty params', function() {
+ expect(OC.buildQueryString()).toEqual('');
+ expect(OC.buildQueryString({})).toEqual('');
+ });
+ it('Encodes regular query strings', function() {
+ expect(OC.buildQueryString({
+ a: 'abc',
+ b: 'def'
+ })).toEqual('a=abc&b=def');
+ });
+ it('Encodes special characters', function() {
+ expect(OC.buildQueryString({
+ unicode: '汉字',
+ })).toEqual('unicode=%E6%B1%89%E5%AD%97');
+ expect(OC.buildQueryString({
+ b: 'spaace value',
+ 'space key': 'normalvalue',
+ 'slash/this': 'amp&ersand'
+ })).toEqual('b=spaace%20value&space%20key=normalvalue&slash%2Fthis=amp%26ersand');
+ });
+ it('Encodes data types and empty values', function() {
+ expect(OC.buildQueryString({
+ 'keywithemptystring': '',
+ 'keywithnull': null,
+ 'keywithundefined': null,
+ something: 'else'
+ })).toEqual('keywithemptystring=&keywithnull&keywithundefined&something=else');
+ expect(OC.buildQueryString({
+ 'booleanfalse': false,
+ 'booleantrue': true
+ })).toEqual('booleanfalse=false&booleantrue=true');
+ expect(OC.buildQueryString({
+ 'number': 123,
+ })).toEqual('number=123');
+ });
+ });
});