Author: reebalazs
Date: Thu Nov 20 16:43:49 2008
New Revision: 60025
Modified:
kukit/kukit.js/branch/1.4/doc/HISTORY.txt
kukit/kukit.js/branch/1.4/kukit/serveraction.js
Log:
Backport from trunk -r60016: Fix or improve calculateAbsoluteURL
Modified: kukit/kukit.js/branch/1.4/doc/HISTORY.txt
==============================================================================
--- kukit/kukit.js/branch/1.4/doc/HISTORY.txt (original)
+++ kukit/kukit.js/branch/1.4/doc/HISTORY.txt Thu Nov 20 16:43:49 2008
@@ -8,6 +8,14 @@
kukit.js - 1.4.3 Released 2008-08-18
+ - Fix or improve calculateAbsoluteURL to handle absolute
+ and relative urls correctly, as well as get rid of the
+ double slash (//) issue.
+ It also satisfies the tests kss_url_param and
+ kss_url_param_multiprop, that now work as intended,
+ with previous workaround removed.
+ [ree]
+
- Replaced license header of third-party sarissa.js
to workaround the license detection of ohloh.
sarissa.js is redistributed under GNU GPL v2
Modified: kukit/kukit.js/branch/1.4/kukit/serveraction.js
==============================================================================
--- kukit/kukit.js/branch/1.4/kukit/serveraction.js (original)
+++ kukit/kukit.js/branch/1.4/kukit/serveraction.js Thu Nov 20 16:43:49 2008
@@ -53,24 +53,40 @@
this.notifyServer();
};
+/*
+ * calculateAbsoluteURL
+ *
+ * Makes absolute site url
+ * - if starts with http:// https:// : no change
+ * - if starts with /: interprets absolute from domain
+ * - otherwise: relative to current context
+ */
this.calculateAbsoluteURL = function(url) {
- //
- // If the url is an absolute path, it is used
- //
- // If the url is not an absolute path, it is put at the end of the context
- // url.
- //
- // example: url='@theview/getName',
- // context='http://your.site.com/portal/folder/object'
- //
- // result='http://your.site.com/portal/folder/object/@@theview/getName'
- //
- if (url.match(RegExp('/^https?:\/\//'))) {
+ // XXX packer breaks on following regexp constant,
+ // so it must be quoted
+ if (url.match(RegExp("/^https?:\/\//"))) {
+ // absolute already
return url;
- } else {
- var result = kukit.engine.baseUrl + url;
- return result;
}
+ var absoluteMatch = url.match(RegExp(/^(\/)(.*)/));
+ var path = kukit.engine.baseUrl;
+ if (absoluteMatch) {
+ // relative to domain
+ var base = path.match(RegExp(/^(.*:\/\/[^\/]*)(\/?)/))[1];
+ // base is like: http://foo.bar without trailing /
+ url = base + url;
+ return url;
+ }
+ // final case: relative to current url
+ // (paranoia: add an / to the path *only* if it is
+ // *not* there)
+ // XXX packer breaks on following
+ // regexp constant, so it must be quoted
+ if (! path.match(RegExp("/$"))) {
+ path += '/';
+ }
+ url = path + url;
+ return url;
};
// Backparameters can be used on command execution.
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins