Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pathologic
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
pathologic
Commits
4b48257d
Commit
4b48257d
authored
15 years ago
by
Garrett Albright
Browse files
Options
Downloads
Patches
Plain Diff
Fix paths of just a slash - [
#817722
] sort of
parent
54c13c66
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pathologic.module
+4
-3
4 additions, 3 deletions
pathologic.module
pathologic.test
+4
-1
4 additions, 1 deletion
pathologic.test
with
8 additions
and
4 deletions
pathologic.module
+
4
−
3
View file @
4b48257d
...
...
@@ -86,12 +86,13 @@ function _pathologic($text, $filter) {
// The pattern is gonna look like:
// ~(href|src|HREF|SRC)="(
// (
// /|
// (internal:|https?://example\.com|https?://example\.org)(/?(index\.php)?(\?q=)?)|
// (?!([#/]|mailto:|.*:/))(
internal:|
\?q=)?
// (?!([#/]|mailto:|.*:/))(\?q=)?
// )
// ([^"]*)
// )~
'pattern'
=>
'~(href|src|HREF|SRC)="(((internal:|'
.
implode
(
'|'
,
$paths
)
.
')(/?(index.php)?(\?q=)?)|(?!([#/]|mailto:|.*:/))(\?q=)?)([^"]*))~'
,
'pattern'
=>
'~(href|src|HREF|SRC)="((
/|
(internal:|'
.
implode
(
'|'
,
$paths
)
.
')(/?(index.php)?(\?q=)?)|(?!([#/]|mailto:|.*:/))(\?q=)?)([^"]*))~'
,
// create_funtion() lets us do lambdas in a really crappy but pre-PHP 5.3-
// compatible way. We're using it here so we can pass the value of
// $filter->settings['absolute'] to the replacement function. We could
...
...
@@ -121,7 +122,7 @@ function _pathologic_replace($matches, $absolute) {
// the path is just one character (just '/'), but url() seems to be okay with
// that.
$parts
[
'path'
]
=
drupal_substr
(
$parts
[
'path'
],
1
);
// Need to parse the query parts
if
(
isset
(
$parts
[
'query'
]))
{
parse_str
(
$parts
[
'query'
],
$qparts
);
...
...
This diff is collapsed.
Click to expand it.
pathologic.test
+
4
−
1
View file @
4b48257d
...
...
@@ -44,6 +44,7 @@ class PathologicTestCase extends DrupalWebTestCase {
drupal_static_reset
(
'filter_formats'
);
// Build some paths to check against
$paths
=
array
(
'front'
=>
url
(
'<front>'
,
array
(
'absolute'
=>
TRUE
)),
'admin'
=>
url
(
'admin'
,
array
(
'absolute'
=>
TRUE
)),
'foo'
=>
url
(
'foo'
,
array
(
'absolute'
=>
TRUE
)),
'foo/bar'
=>
url
(
'foo/bar'
,
array
(
'absolute'
=>
TRUE
)),
...
...
@@ -66,11 +67,13 @@ class PathologicTestCase extends DrupalWebTestCase {
$this
->
assertEqual
(
check_markup
(
'<a href="internal:foo"><img src="internal:foo/bar?baz=qux"></a>'
,
4
),
'<a href="'
.
$paths
[
'foo'
]
.
'"><img src="'
.
$paths
[
'foo/bar?baz=qux'
]
.
'"></a>'
,
t
(
'Path Filter back compatibility'
));
// Also considered local
$this
->
assertEqual
(
check_markup
(
'<a href="http://example.com/foo"><img src="http://example.com/index.php?q=foo/bar&baz=qux"></a>'
,
4
),
'<a href="'
.
$paths
[
'foo'
]
.
'"><img src="'
.
$paths
[
'foo/bar?baz=qux'
]
.
'"></a>'
,
t
(
'Also considered local'
));
// Asterisks
local paths
// Asterisks
in domain names - [#758118]
$this
->
assertEqual
(
check_markup
(
'<a href="http://foo.example.net/foo"><img src="http://example.org/qux/bar/foo"></a>'
,
4
),
'<a href="'
.
$paths
[
'foo'
]
.
'"><img src="'
.
$paths
[
'foo'
]
.
'"></a>'
,
t
(
'Asterisk in domain'
));
// Non-absolute - Note we're using format 5 here
$this
->
assertEqual
(
check_markup
(
'<a href="?q=quuux"><img src="quuux"></a>'
,
5
),
'<a href="'
.
$paths
[
'quuux'
]
.
'"><img src="'
.
$paths
[
'quuux'
]
.
'"></a>'
,
t
(
'Non-absolute path output'
));
// Upper-case HREF and SRC params - [#760876]
$this
->
assertEqual
(
check_markup
(
'<A HREF="foo"><IMG SRC="foo/bar"></A>'
,
4
),
'<A HREF="'
.
$paths
[
'foo'
]
.
'"><IMG SRC="'
.
$paths
[
'foo/bar'
]
.
'"></A>'
,
t
(
'Old-skool upper-case attribute names'
));
// Paths with just slashes - [#817722] sort of
$this
->
assertEqual
(
check_markup
(
'<a href="/"></a>'
,
4
),
'<a href="'
.
$paths
[
'front'
]
.
'"></a>'
,
t
(
'Linking to front page with href="/"'
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment