Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
persona
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hexang 息壤平台
persona
Commits
27ddad5f
Commit
27ddad5f
authored
12 years ago
by
Lloyd Hilaiel
Browse files
Options
Downloads
Plain Diff
Merge pull request #2015 from zaach/issue1981
new regex for matching origins - issue #1981
parents
13ea8a6b
3ed77502
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/validate.js
+18
-3
18 additions, 3 deletions
lib/validate.js
with
18 additions
and
3 deletions
lib/validate.js
+
18
−
3
View file @
27ddad5f
...
...
@@ -38,9 +38,24 @@ var types = {
JSON
.
parse
(
x
);
},
origin
:
function
(
x
)
{
// allow single hostnames, e.g. localhost
if
(
typeof
x
!==
'
string
'
||
!
x
.
match
(
/^https
?
:
\/\/[
a-z
\d
_-
]
+
(\.[
a-z
\d
_-
]
+
)
*
(
:
\d
+
)?
$/i
))
{
throw
"
not a valid origin
"
;
/* origin regex
/^ // beginning
https?:\/\/ // starts with http:// or https://
(?=.{1,254}(?::|$)) // hostname must be within 1-254 characters
(?: // match hostname part (<part>.<part>...)
(?!\d|-) // cannot start with a digit or dash
(?![a-z0-9\-]{1,62}- // part cannot end with a dash
(?:\.|:|$)) // (end of part will be '.', ':', or end of str)
[a-z0-9\-]{1,63}\b // part will be 1-63 letters, numbers, or dashes
(?!\.$) // final part cannot end with a '.'
\.? // part followed by '.' unless final part
)+ // one or more hostname parts
(:\d+)? // optional port
$/i; // end; case-insensitive
*/
var
regex
=
/^https
?
:
\/\/(?=
.
{1,254}(?:
:|$
))(?:(?!\d
|-
)(?![
a-z0-9
\-]{1,62}
-
(?:\.
|:|$
))[
a-z0-9
\-]{1,63}\b(?!\.
$
)\.?)
+
(
:
\d
+
)?
$/i
;
if
(
typeof
x
!==
'
string
'
||
!
x
.
match
(
regex
))
{
throw
new
Error
(
"
not a valid origin
"
);
}
}
};
...
...
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