Skip to content

Commit

Permalink
[Chore] Simplify regexp usages
Browse files Browse the repository at this point in the history
  • Loading branch information
aeqz committed Dec 30, 2022
1 parent 0b4ce99 commit 05fe537
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ There are several ways to fix this:
- to: "https?://forbidden.com.*"
on: 307
outcome: invalid
- from: "^http://.*"
to: "^https://.*"
- from: "http://.*"
to: "https://.*"
outcome: follow
```

Expand Down
2 changes: 1 addition & 1 deletion src/Xrefcheck/Config/Default.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exclusions:
# List of POSIX extended regular expressions.
ignoreExternalRefsTo:
# Ignore localhost links by default
- ^(https?|ftps?)://(localhost|127\\.0\\.0\\.1).*
- (https?|ftps?)://(localhost|127\\.0\\.0\\.1).*

# Networking parameters.
networking:
Expand Down
14 changes: 7 additions & 7 deletions tests/Test/Xrefcheck/RedirectConfigSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test_redirectRequests = testGroup "Redirect config tests"
[ testCase "Do match" $ do
setRef <- newIORef mempty
checkLinkAndProgressWithServer
(configMod [RedirectRule Nothing (regex "^.*/ok$") Nothing RROValid] [])
(configMod [RedirectRule Nothing (regex ".*/ok") Nothing RROValid] [])
setRef
mockRedirect
(link "/permanent-redirect")
Expand All @@ -58,7 +58,7 @@ test_redirectRequests = testGroup "Redirect config tests"
, testCase "Do not match" $ do
setRef <- newIORef mempty
checkLinkAndProgressWithServer
(configMod [RedirectRule Nothing (regex "^.*/no-ok$") (Just RROPermanent) RROValid] [])
(configMod [RedirectRule Nothing (regex ".*/no-ok") (Just RROPermanent) RROValid] [])
setRef
mockRedirect
(link "/permanent-redirect")
Expand All @@ -69,7 +69,7 @@ test_redirectRequests = testGroup "Redirect config tests"
[ testCase "Do match" $ do
setRef <- newIORef mempty
checkLinkAndProgressWithServer
(configMod [RedirectRule (regex "^.*/permanent-.*$") Nothing Nothing RROValid] [])
(configMod [RedirectRule (regex ".*/permanent-.*") Nothing Nothing RROValid] [])
setRef
mockRedirect
(link "/permanent-redirect")
Expand All @@ -78,7 +78,7 @@ test_redirectRequests = testGroup "Redirect config tests"
, testCase "Do not match" $ do
setRef <- newIORef mempty
checkLinkAndProgressWithServer
(configMod [RedirectRule (regex "^.*/temporary-.*$") Nothing (Just RROPermanent) RROValid] [])
(configMod [RedirectRule (regex ".*/temporary-.*") Nothing (Just RROPermanent) RROValid] [])
setRef
mockRedirect
(link "/permanent-redirect")
Expand All @@ -89,7 +89,7 @@ test_redirectRequests = testGroup "Redirect config tests"
[ testCase "Do match" $ do
setRef <- newIORef mempty
checkLinkAndProgressWithServer
(configMod [RedirectRule (regex "^.*/follow[0-9]$") (regex "^.*/ok$") (Just (RROCode 307)) RROInvalid] [])
(configMod [RedirectRule (regex ".*/follow[0-9]") (regex "^.*/ok$") (Just (RROCode 307)) RROInvalid] [])
setRef
mockRedirect
(link "/follow3")
Expand All @@ -98,7 +98,7 @@ test_redirectRequests = testGroup "Redirect config tests"
, testCase "Do not match" $ do
setRef <- newIORef mempty
checkLinkAndProgressWithServer
(configMod [RedirectRule (regex "^.*/follow[0-9]$") (regex "^.*/ok$") (Just (RROCode 307)) RROInvalid] [])
(configMod [RedirectRule (regex ".*/follow[0-9]") (regex "^.*/ok$") (Just (RROCode 307)) RROInvalid] [])
setRef
mockRedirect
(link "/follow2")
Expand Down Expand Up @@ -137,7 +137,7 @@ test_redirectRequests = testGroup "Redirect config tests"
, testCase "Mixed with ignore" $ do
setRef <- newIORef mempty
checkLinkAndProgressWithServer
(configMod [RedirectRule Nothing Nothing (Just (RROCode 307)) RROInvalid, RedirectRule Nothing Nothing Nothing RROFollow] (maybeToList (regex "^.*/follow3$")))
(configMod [RedirectRule Nothing Nothing (Just (RROCode 307)) RROInvalid, RedirectRule Nothing Nothing Nothing RROFollow] (maybeToList (regex ".*/follow3")))
setRef
mockRedirect
(link "/follow1")
Expand Down
2 changes: 1 addition & 1 deletion tests/configs/github-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exclusions:
# List of POSIX extended regular expressions.
ignoreExternalRefsTo:
# Ignore localhost links by default
- ^(https?|ftps?)://(localhost|127\.0\.0\.1).*
- (https?|ftps?)://(localhost|127\.0\.0\.1).*

# Networking parameters.
networking:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

exclusions:
ignoreExternalRefsTo:
- ^(https?|ftps?)://(localhost|127\.0\.0\.1).*
- (https?|ftps?)://(localhost|127\.0\.0\.1).*

scanners:
markdown:
Expand Down
1 change: 0 additions & 1 deletion tests/golden/check-redirect-parse/bad-code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ scanners:
networking:
externalRefRedirects:
- outcome: valid
to: ^.*$
on: 404
1 change: 0 additions & 1 deletion tests/golden/check-redirect-parse/bad-on.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ scanners:
networking:
externalRefRedirects:
- outcome: valid
to: ^.*$
on: premanent
2 changes: 1 addition & 1 deletion tests/golden/check-redirect-parse/full-rule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ scanners:
networking:
externalRefRedirects:
- outcome: valid
to: ^https://.*$
to: https://.*
on: permanent
2 changes: 1 addition & 1 deletion tests/golden/check-redirect-parse/no-outcome.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ networking:
externalRefRedirects:
- outcome: valid
on: temporary
- to: ^https://.*$
- to: https://.*
on: temporary
2 changes: 1 addition & 1 deletion tests/golden/check-redirect-parse/only-outcome-to.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ scanners:
networking:
externalRefRedirects:
- outcome: valid
to: ^https://.*$
to: https://.*

0 comments on commit 05fe537

Please sign in to comment.