From 05fe537ae1d7d04c247a03707dc7b63d1ab89a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Enr=C3=ADquez?= Date: Wed, 28 Dec 2022 17:37:58 +0100 Subject: [PATCH] [Chore] Simplify regexp usages --- README.md | 4 ++-- src/Xrefcheck/Config/Default.hs | 2 +- tests/Test/Xrefcheck/RedirectConfigSpec.hs | 14 +++++++------- tests/configs/github-config.yaml | 2 +- .../config-check-disabled.yaml | 2 +- tests/golden/check-redirect-parse/bad-code.yaml | 1 - tests/golden/check-redirect-parse/bad-on.yaml | 1 - tests/golden/check-redirect-parse/full-rule.yaml | 2 +- tests/golden/check-redirect-parse/no-outcome.yaml | 2 +- .../check-redirect-parse/only-outcome-to.yaml | 2 +- 10 files changed, 15 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 42bde3b0..3239f056 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/src/Xrefcheck/Config/Default.hs b/src/Xrefcheck/Config/Default.hs index efdb31f9..86eec9e2 100644 --- a/src/Xrefcheck/Config/Default.hs +++ b/src/Xrefcheck/Config/Default.hs @@ -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: diff --git a/tests/Test/Xrefcheck/RedirectConfigSpec.hs b/tests/Test/Xrefcheck/RedirectConfigSpec.hs index 25043f24..70fa2f31 100644 --- a/tests/Test/Xrefcheck/RedirectConfigSpec.hs +++ b/tests/Test/Xrefcheck/RedirectConfigSpec.hs @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") diff --git a/tests/configs/github-config.yaml b/tests/configs/github-config.yaml index dcd09bdb..adf55523 100644 --- a/tests/configs/github-config.yaml +++ b/tests/configs/github-config.yaml @@ -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: diff --git a/tests/golden/check-ignoreExternalRefsTo/config-check-disabled.yaml b/tests/golden/check-ignoreExternalRefsTo/config-check-disabled.yaml index df6ea981..351ac3d0 100644 --- a/tests/golden/check-ignoreExternalRefsTo/config-check-disabled.yaml +++ b/tests/golden/check-ignoreExternalRefsTo/config-check-disabled.yaml @@ -4,7 +4,7 @@ exclusions: ignoreExternalRefsTo: - - ^(https?|ftps?)://(localhost|127\.0\.0\.1).* + - (https?|ftps?)://(localhost|127\.0\.0\.1).* scanners: markdown: diff --git a/tests/golden/check-redirect-parse/bad-code.yaml b/tests/golden/check-redirect-parse/bad-code.yaml index b9233a8f..715e8dd9 100644 --- a/tests/golden/check-redirect-parse/bad-code.yaml +++ b/tests/golden/check-redirect-parse/bad-code.yaml @@ -9,5 +9,4 @@ scanners: networking: externalRefRedirects: - outcome: valid - to: ^.*$ on: 404 diff --git a/tests/golden/check-redirect-parse/bad-on.yaml b/tests/golden/check-redirect-parse/bad-on.yaml index 1c3d85bf..bd56376d 100644 --- a/tests/golden/check-redirect-parse/bad-on.yaml +++ b/tests/golden/check-redirect-parse/bad-on.yaml @@ -9,5 +9,4 @@ scanners: networking: externalRefRedirects: - outcome: valid - to: ^.*$ on: premanent diff --git a/tests/golden/check-redirect-parse/full-rule.yaml b/tests/golden/check-redirect-parse/full-rule.yaml index a0f7154d..69ff096a 100644 --- a/tests/golden/check-redirect-parse/full-rule.yaml +++ b/tests/golden/check-redirect-parse/full-rule.yaml @@ -9,5 +9,5 @@ scanners: networking: externalRefRedirects: - outcome: valid - to: ^https://.*$ + to: https://.* on: permanent diff --git a/tests/golden/check-redirect-parse/no-outcome.yaml b/tests/golden/check-redirect-parse/no-outcome.yaml index ff5eab86..9cf856c5 100644 --- a/tests/golden/check-redirect-parse/no-outcome.yaml +++ b/tests/golden/check-redirect-parse/no-outcome.yaml @@ -10,5 +10,5 @@ networking: externalRefRedirects: - outcome: valid on: temporary - - to: ^https://.*$ + - to: https://.* on: temporary diff --git a/tests/golden/check-redirect-parse/only-outcome-to.yaml b/tests/golden/check-redirect-parse/only-outcome-to.yaml index bcb1dc6a..d5ef9d75 100644 --- a/tests/golden/check-redirect-parse/only-outcome-to.yaml +++ b/tests/golden/check-redirect-parse/only-outcome-to.yaml @@ -9,4 +9,4 @@ scanners: networking: externalRefRedirects: - outcome: valid - to: ^https://.*$ + to: https://.*