Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
crawl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
crawl
Commits
efe98903
Commit
efe98903
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
relax the CSS url() regexp
parent
f0c14e5e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
analysis/links.go
+10
-5
10 additions, 5 deletions
analysis/links.go
with
10 additions
and
5 deletions
analysis/links.go
+
10
−
5
View file @
efe98903
...
...
@@ -14,7 +14,7 @@ import (
)
var
(
urlcssRx
=
regexp
.
MustCompile
(
`
background
.*:.*url\(["']?([^'"\)]+)["']?\)`
)
urlcssRx
=
regexp
.
MustCompile
(
`.*:.*url\(["']?([^'"\)]+)["']?\)`
)
linkMatches
=
[]
struct
{
tag
string
...
...
@@ -32,6 +32,9 @@ func GetLinks(resp *http.Response) ([]*url.URL, error) {
ctype
:=
resp
.
Header
.
Get
(
"Content-Type"
)
if
strings
.
HasPrefix
(
ctype
,
"text/html"
)
{
// Use goquery to extract links from the parsed HTML
// contents (query patterns are described in the
// linkMatches table).
doc
,
err
:=
goquery
.
NewDocumentFromResponse
(
resp
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -44,6 +47,8 @@ func GetLinks(resp *http.Response) ([]*url.URL, error) {
})
}
}
else
if
strings
.
HasPrefix
(
ctype
,
"text/css"
)
{
// Use a simple (and actually quite bad) regular
// expression to extract "url()" links from CSS.
if
data
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
);
err
==
nil
{
for
_
,
val
:=
range
urlcssRx
.
FindAllStringSubmatch
(
string
(
data
),
-
1
)
{
outlinks
=
append
(
outlinks
,
val
[
1
])
...
...
@@ -51,7 +56,8 @@ func GetLinks(resp *http.Response) ([]*url.URL, error) {
}
}
// Uniquify and parse outbound links.
// Parse outbound links relative to the request URI, and
// return unique results.
var
result
[]
*
url
.
URL
links
:=
make
(
map
[
string
]
*
url
.
URL
)
for
_
,
val
:=
range
outlinks
{
...
...
@@ -59,9 +65,8 @@ func GetLinks(resp *http.Response) ([]*url.URL, error) {
links
[
linkurl
.
String
()]
=
linkurl
}
}
for
_
,
link
:=
range
links
{
result
=
append
(
result
,
link
)
for
_
,
u
:=
range
links
{
result
=
append
(
result
,
u
)
}
return
result
,
nil
}
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