Ticket #105 (closed defect: fixed)
Incorrect regular expression in fixRelativeLinks function invalidates SelfNamedAnchors fix
| Reported by: | egk10@… | Owned by: | gogo |
|---|---|---|---|
| Priority: | normal | Milestone: | Version 1.0 |
| Component: | Xinha Core | Version: | trunk |
| Severity: | normal | Keywords: | |
| Cc: |
Description
The fixRelativeLinks function of htmlarea.js contains an incorrect regular expression which causes only the first instance of a self-named-anchor (e.g. <a href="#mybookmark">) to be 'fixed' when stripSelfNamedAnchors is set. The incorrect code is:
var stripRe = new RegExp?(document.location.href.replace HTMLArea.RE_Specials, '\\$1') + '(#.*)', 'g');
The problem is that (#.*) matches the first anchor plus ALL CHARACTERS (.) to the end of the document (or the next newline)! Hence, any subsequent anchors are ignored. The correct parenthetical expression should be (#[\'\"]*), which will match from the # of the first anchor up to and not including the next single or double quote mark. I have verified this fix. However, there is a further problem with the fixRelativeLinks function running on IE WinXP. IE prepends only the protocol and hostname to self-named anchors, so instead of reading href="#mybookmark", we get href="http://www.myhost.com/#mybookmark", which is usually nonsense. The fixRelativeLinks function doesn't search for this instance. The following correction to the first if clause of the function works for me IF I SET config.baseHref to http://www.myhost.com/, but has not been tested on Firefox:
HTMLArea.prototype.fixRelativeLinks = function(html) {
if(typeof this.config.stripSelfNamedAnchors != 'undefined' && this.config.stripSelfNamedAnchors) {
var stripRe = null; if(typeof this.config.baseHref != 'undefined' && this.config.baseHref != null) {
stripRe = new RegExp?(this.config.baseHref.replace(HTMLArea.RE_Specials, '\\$1') + '(#[\'\"]*)', 'g');
} else {
stripRe = new RegExp?(document.location.href.replace(HTMLArea.RE_Specials, '\\$1') + '(#[\'\"]*)', 'g');
} html = html.replace(stripRe, '$1');
}
