first character not present
ac4lt - February 17, 2006 - 13:49
| Project: | Relative Link Filter |
| Version: | 4.6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | active |
Description
Fantastic idea and it solves a problem I have with mails sent out via Simplenews that have relative links that work in the email but not on the website. Well, it would except for this:
I have a links that look like:
<a href="#item1">item 1</a>And if the node is:
http://www.example.com/node/302
then what comes out is:
http://www.example.com/ode/302#item1

#1
It appears the problem is on line 21 (I'm using rev. 1.1.2.1). The strlen($dir)+1 shouldn't have the '+1'. That appears to fix it on my site although I haven't tested thoroughly. I'd submit a patch but I'm on a system where I don't have any tools to make one available.
#2
I found the same problem and fixed it the same way. Here's the patch. Would somebody please apply the thing to these bits ASAP?
#3
For those who still need this module in 4.7 (if you're feeding content directly in the database, weren't able to get the link update script working in the upgrade, etc.), these are things to consider:
#flag specific links so as not to alter (via hrefnot)$text = preg_replace('( (href|src)="(/|http:|https:|ftp:|mailto:|.))', ' \1not="\2', $text);
#correct named anchors and then flag to skip (via hrefnot)
$text = preg_replace('( href="#)', " hrefnot=\"/$uri#", $text);
#correct all other links with an updated path, and...
$text = preg_replace('( (href|src)=")', " \\1=\"/$uridir", $text);
#go back over the first two hrefnot to restore viability
$text = preg_replace('( (href|src)not=")', ' \1="', $text);
Note that I added "." to the initial exclusions list...if someone had a relative path using dots, the original regex for this filter would totally make a mess of it. I also added a leading slash to the middle two replacements - without them, the paths were being doubled (ie., http://domain/node/node/1234 instead of http://domain/node/1234 - and made the correction already stated above regarding the -1 (which incorrectly turned "node" into "ode"). I realize that going forward, this is all supposedly unnecessary in 4.7, but it's a good tool to have and seems a lot smarter than hard-coding a base href path in the site themes.