Skip to content

🐛 fix: Align cache hashes#1248

Merged
drptbl merged 16 commits intodevfrom
fix/align-cache-hashes
Feb 5, 2025
Merged

🐛 fix: Align cache hashes#1248
drptbl merged 16 commits intodevfrom
fix/align-cache-hashes

Conversation

@localtechboy
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Nov 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
synpress ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 5, 2025 9:50pm

@localtechboy localtechboy force-pushed the fix/align-cache-hashes branch from 3f1515b to 609f1a5 Compare December 3, 2024 10:19
@@ -0,0 +1,5 @@
export default {
baseUrl: 'https://www.alphabot.app/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is alphabot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the page user added as an example - this test case is more for you as a prove that this issue has been fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,12 @@
export function extractWalletSetupFunction(sourceCode: string): string {
const match = sourceCode.match(
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with 'defineWalletSetup(,async()=>{' and containing many repetitions of 'z'.

Copilot Autofix

AI about 1 year ago

To fix the problem, we need to modify the regular expression to remove the ambiguity and reduce the potential for excessive backtracking. This can be achieved by making the sub-expressions more specific and avoiding patterns that can match the same string in multiple ways. Specifically, we can replace [^{}]* with a more precise pattern that matches the intended input without allowing for excessive backtracking.

The best way to fix the problem is to rewrite the regular expression to avoid ambiguous sub-expressions and nested quantifiers. We can achieve this by using non-capturing groups and more specific character classes.

Suggested changeset 1
packages/cache/src/utils/extractWalletSetupFunction.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/cache/src/utils/extractWalletSetupFunction.ts b/packages/cache/src/utils/extractWalletSetupFunction.ts
--- a/packages/cache/src/utils/extractWalletSetupFunction.ts
+++ b/packages/cache/src/utils/extractWalletSetupFunction.ts
@@ -2,3 +2,3 @@
   const match = sourceCode.match(
-    /defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/
+    /defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}{}]*|{(?:[^{}{}]*|{[^{}{}]*})*})*})\s*\)/
   )
EOF
@@ -2,3 +2,3 @@
const match = sourceCode.match(
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}{}]*|{(?:[^{}{}]*|{[^{}{}]*})*})*})\s*\)/
)
Copilot is powered by AI and may make mistakes. Always verify output.
@@ -0,0 +1,12 @@
export function extractWalletSetupFunction(sourceCode: string): string {
const match = sourceCode.match(
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with 'defineWalletSetup(,async()=>{{' and containing many repetitions of 'z'.

Copilot Autofix

AI about 1 year ago

To fix the problem, we need to modify the regular expression to remove the ambiguity that leads to catastrophic backtracking. This can be achieved by making the pattern more specific and less ambiguous. In this case, we can replace the ambiguous [^{}]* with a more precise pattern that matches the expected structure of the input.

The best way to fix the problem without changing existing functionality is to rewrite the regular expression to avoid nested quantifiers and ambiguous patterns. Specifically, we can use a non-recursive approach to match the nested braces and their contents.

Suggested changeset 1
packages/cache/src/utils/extractWalletSetupFunction.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/cache/src/utils/extractWalletSetupFunction.ts b/packages/cache/src/utils/extractWalletSetupFunction.ts
--- a/packages/cache/src/utils/extractWalletSetupFunction.ts
+++ b/packages/cache/src/utils/extractWalletSetupFunction.ts
@@ -2,3 +2,3 @@
   const match = sourceCode.match(
-    /defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/
+    /defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{[^{}]*(?:{[^{}]*}[^{}]*)*})\s*\)/
   )
EOF
@@ -2,3 +2,3 @@
const match = sourceCode.match(
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{[^{}]*(?:{[^{}]*}[^{}]*)*})\s*\)/
)
Copilot is powered by AI and may make mistakes. Always verify output.
@drptbl drptbl merged commit e3b1b7c into dev Feb 5, 2025
9 checks passed
@drptbl drptbl deleted the fix/align-cache-hashes branch February 5, 2025 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants