Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Friend <hello@nathanfriend.io>2021-08-21 19:37:34 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-08-25 10:29:45 +0300
commit65188a6f442d2fa5f34be815564c151f3a52e8a7 (patch)
tree9dcafe2a982470ca51fcc99ce4ba623faa49be98 /internal/redirects/redirects.go
parent14c87e2392d2ac64a3b820cb60b829d45d58443f (diff)
feat: Add _redirects max rule count validation
This commit adds a new validation that ensures a _redirects file doesn't contain too many rules. Changelog: changed
Diffstat (limited to 'internal/redirects/redirects.go')
-rw-r--r--internal/redirects/redirects.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/internal/redirects/redirects.go b/internal/redirects/redirects.go
index 79fa8dd6..fafeaf4b 100644
--- a/internal/redirects/redirects.go
+++ b/internal/redirects/redirects.go
@@ -30,6 +30,9 @@ const (
// maxPathSegments is used to limit the number of path segments allowed in rules URLs
maxPathSegments = 25
+ // maxRuleCount is used to limit the total number of rules allowed in _redirects
+ maxRuleCount = 1000
+
// FFEnablePlaceholders used to check whether placeholder matching is enabled or not
FFEnablePlaceholders = "FF_ENABLE_PLACEHOLDERS"
)
@@ -51,7 +54,8 @@ var (
errNoParams = errors.New("params not supported")
errUnsupportedStatus = errors.New("status not supported")
errNoForce = errors.New("force! not supported")
- errTooManyPathSegments = errors.New("url path cannot contain more than 25 forward slashes")
+ errTooManyPathSegments = fmt.Errorf("url path cannot contain more than %d forward slashes", maxPathSegments)
+ errTooManyRules = fmt.Errorf("_redirects file may not contain more than %d rules", maxRuleCount)
regexpPlaceholder = regexp.MustCompile(`(?i)/:[a-z]+`)
)
@@ -69,6 +73,10 @@ func (r *Redirects) Status() string {
messages := make([]string, 0, len(r.rules)+1)
messages = append(messages, fmt.Sprintf("%d rules", len(r.rules)))
+ if err := validateRedirectsFile(r); err != nil {
+ messages = append(messages, fmt.Sprintf("error: %s", err.Error()))
+ }
+
for i, rule := range r.rules {
if err := validateRule(rule); err != nil {
messages = append(messages, fmt.Sprintf("rule %d: error: %s", i+1, err.Error()))