Author: reebalazs
Date: Thu Nov 20 13:05:09 2008
New Revision: 60015
Modified:
kukit/kukit.js/trunk/doc/HISTORY.txt
kukit/kukit.js/trunk/kukit/serveraction.js
Log:
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.
Modified: kukit/kukit.js/trunk/doc/HISTORY.txt
==============================================================================
--- kukit/kukit.js/trunk/doc/HISTORY.txt (original)
+++ kukit/kukit.js/trunk/doc/HISTORY.txt Thu Nov 20 13:05:09 2008
@@ -11,6 +11,14 @@
still broken in IE6)
[gotcha]
+ - 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/trunk/kukit/serveraction.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/serveraction.js (original)
+++ kukit/kukit.js/trunk/kukit/serveraction.js Thu Nov 20 13:05:09 2008
@@ -63,24 +63,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