Opened 14 years ago

Closed 14 years ago

#870 closed defect (fixed)

fixRelativeLinks strips baseHref from content

Reported by: ray Owned by: gogo
Priority: normal Milestone:
Component: Xinha Core Version:
Severity: normal Keywords:


From rmassart from the forum :
I had the problem that the baseHref replacement was also replacing inline text. So if I have the following html snippet:

<a href=""></a>

After opening and saving this content in Xinha it got converted to:

<a href="/test">/test</a>

When really it should be:

<a href="/test"></a>

ie the replacement was occurring on ALL matches in the content, not just those that are actually URLs.

I altered this by changing the following code in the fixRelativeLinks function:

    var baseRe = null
    if(typeof this.config.baseHref != 'undefined' && this.config.baseHref != null)
      baseRe = new RegExp(this.config.baseHref.replace(HTMLArea.RE_Specials, '\\$1'), 'g');
      baseRe = new RegExp(document.location.href.replace(/([^\/]*\/?)$/, '').replace(HTMLArea.RE_Specials, '\\$1'), 'g');

    html = html.replace(baseRe, '');


    var baseRe = null
    if(typeof this.config.baseHref != 'undefined' && this.config.baseHref != null)
      baseRe = new RegExp("((href|src|background)=[\'\"])(" + this.config.baseHref.replace(HTMLArea.RE_Specials, '\\$1') + ")", 'g');
      baseRe = new RegExp("((href|src|background)=[\'\"])(" + document.location.href.replace(/([^\/]*\/?)$/, '').replace(HTMLArea.RE_Specials, '\\$1') + ")", 'g');

    html = html.replace(baseRe, '$1');

This is not a thorougly tested change and I don't know if this is something useful for others, but I thought I'd post it here anyway.

Change History (2)

comment:1 Changed 14 years ago by ray

I think this is absolutely reasonable

comment:2 Changed 14 years ago by ray

  • Resolution set to fixed
  • Status changed from new to closed

Committed Changeset [617]

Note: See TracTickets for help on using tickets.