-
Notifications
You must be signed in to change notification settings - Fork 167
fix: add invalid regex validation for commitConfig
#1355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jescalada
merged 19 commits into
finos:main
from
jescalada:1336-fix-invalid-regex-commitConfig
Feb 16, 2026
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e9e79b8
feat: add validation function for commitConfig regex
jescalada c57b480
fix: add custom validation for config load and reload
jescalada 2bbd787
fix: extract validators into own file and implement validation chain
jescalada 50041fc
test: add configValidators test file
jescalada 6315345
test: add ConfigLoader tests for reloadConfiguration
jescalada a1984ee
test: add src/config/index tests, modify validation to throw error in…
jescalada add33b1
Merge branch 'main' into 1336-fix-invalid-regex-commitConfig
jescalada 056c086
Merge branch 'main' into 1336-fix-invalid-regex-commitConfig
jescalada 5a5775b
Merge branch 'main' into 1336-fix-invalid-regex-commitConfig
jescalada 3fd5e38
fix: emit config changed event only when valid
jescalada 0bb6a29
fix: incorrect test logic for skipping reload on invalid config
jescalada 7f3f632
Merge branch 'main' into 1336-fix-invalid-regex-commitConfig
kriswest a27ce94
feat: add commitConfig.diff.block.providers regex check and tests
jescalada d7ea084
fix: double loadFullConfiguration execution and unnecessary casting
jescalada c852d0e
Merge branch 'main' into 1336-fix-invalid-regex-commitConfig
jescalada 60be1d4
feat: extract config loading and parsing logic into validators.ts hel…
jescalada 0feedbd
test: update ConfigLoader tests to match new error messages
jescalada 3d977e7
refactor: config regex validation logic into reusable functions
jescalada 07da631
Merge branch 'main' into 1336-fix-invalid-regex-commitConfig
jescalada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { Convert, GitProxyConfig } from './generated/config'; | ||
|
|
||
| const validationChain = [validateCommitConfig]; | ||
|
|
||
| /** | ||
| * Executes all custom validators on the configuration | ||
| * @param config The configuration to validate | ||
| * @returns true if the configuration is valid, false otherwise | ||
| */ | ||
| export const validateConfig = (config: GitProxyConfig): boolean => { | ||
| return validationChain.every((validator) => validator(config)); | ||
| }; | ||
|
|
||
| /** | ||
| * Validates that commit configuration uses valid regular expressions. | ||
| * @param config The commit configuration to validate | ||
| * @returns true if the commit configuration is valid, false otherwise | ||
| */ | ||
| function validateCommitConfig(config: GitProxyConfig): boolean { | ||
| return ( | ||
| validateConfigRegex(config, 'commitConfig.author.email.local.block') && | ||
| validateConfigRegex(config, 'commitConfig.author.email.domain.allow') && | ||
| validateConfigRegex(config, 'commitConfig.message.block.patterns') && | ||
| validateConfigRegex(config, 'commitConfig.diff.block.patterns') && | ||
| validateConfigRegex(config, 'commitConfig.diff.block.providers') | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Validates that a regular expression is valid. | ||
| * @param pattern The regular expression to validate | ||
| * @param context The context of the regular expression | ||
| * @returns true if the regular expression is valid, false otherwise | ||
| */ | ||
| function isValidRegex(pattern: string, context: string): boolean { | ||
| try { | ||
| new RegExp(pattern); | ||
| return true; | ||
| } catch { | ||
| console.error(`Invalid regular expression for ${context}: ${pattern}`); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Validates that a value in the configuration is a valid regular expression. | ||
| * @param config The configuration to validate | ||
| * @param path The path to the value to validate | ||
| * @returns true if the value is a valid regular expression, false otherwise | ||
| */ | ||
| function validateConfigRegex(config: GitProxyConfig, path: string): boolean { | ||
| const getValueAtPath = (obj: unknown, path: string): unknown => { | ||
| return path.split('.').reduce((current, key) => { | ||
| if (current == null || typeof current !== 'object') { | ||
| return undefined; | ||
| } | ||
| return (current as Record<string, unknown>)[key]; | ||
| }, obj); | ||
| }; | ||
|
|
||
| const value = getValueAtPath(config, path); | ||
|
|
||
| if (!value) return true; | ||
|
|
||
| if (typeof value === 'string') { | ||
| return isValidRegex(value, path); | ||
| } | ||
|
|
||
| if (Array.isArray(value)) { | ||
| for (const pattern of value) { | ||
| if (!isValidRegex(pattern, path)) return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| if (typeof value === 'object') { | ||
| return Object.values(value).every((pattern) => isValidRegex(pattern as string, path)); | ||
| } | ||
|
jescalada marked this conversation as resolved.
|
||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Loads and parses a GitProxyConfig object from a given context and loading strategy. | ||
| * @param context The context of the configuration | ||
| * @param loader The loading strategy to use | ||
| * @returns The parsed GitProxyConfig object | ||
| */ | ||
| export async function loadConfig( | ||
| context: string, | ||
| loader: () => Promise<string>, | ||
| ): Promise<GitProxyConfig> { | ||
| const raw = await loader(); | ||
| return parseGitProxyConfig(raw, context); | ||
| } | ||
|
|
||
| /** | ||
| * Parses a raw string into a GitProxyConfig object. | ||
| * @param raw The raw string to parse | ||
| * @param context The context of the configuration | ||
| * @returns The parsed GitProxyConfig object | ||
| */ | ||
| function parseGitProxyConfig(raw: string, context: string): GitProxyConfig { | ||
| try { | ||
| return Convert.toGitProxyConfig(raw); | ||
| } catch (error) { | ||
| throw new Error( | ||
| `Invalid configuration format in ${context}: ${error instanceof Error ? error.message : 'Unknown error'}`, | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.