Opened 13 years ago

Closed 13 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:
Cc:

Description

From rmassart from the forum http://xinha.gogo.co.nz/punbb/viewtopic.php?pid=4028 :
I had the problem that the baseHref replacement was also replacing inline text. So if I have the following html snippet:

<a href="http://www.example.com/test">http://www.example.com/test</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">http://www.example.com/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');
    }
    else
    {
      baseRe = new RegExp(document.location.href.replace(/([^\/]*\/?)$/, '').replace(HTMLArea.RE_Specials, '\\$1'), 'g');
    }

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

to:

    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');
    }
    else
    {
      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 13 years ago by ray

I think this is absolutely reasonable

comment:2 Changed 13 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.