Commit d5d6c396 authored by nextime's avatar nextime

Fix JavaScript syntax errors in complex regex patterns

- Simplified regex patterns to avoid escaping issues
- Removed overly complex regex constructions that caused 'missing ) after argument list' errors
- Maintained functionality while improving reliability
- Fixed responseMatch pattern extraction for malformed JSON handling
parent c8610caf
...@@ -498,17 +498,14 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro ...@@ -498,17 +498,14 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro
// Clean the text first // Clean the text first
const cleanedText = cleanJsonText(text); const cleanedText = cleanJsonText(text);
// Look for JSON patterns with our unique ID // Look for JSON patterns with our unique ID - simplified patterns
const jsonPatterns = [ const jsonPatterns = [
// Standard JSON object patterns // Standard JSON object patterns - simplified
new RegExp('\\{[^{}]*"id"\\s*:\\s*"[^"]*' + requestId + '[^"]*"[^{}]*"response"\\s*:\\s*"([^"\\\\]|\\\\.)*"[^{}]*\\}', 'g'), new RegExp('\\{[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*"response"[^{}]*"[^"]*"[^{}]*\\}', 'g'),
new RegExp('\\{[^{}]*"response"\\s*:\\s*"([^"\\\\]|\\\\.)*"[^{}]*"id"\\s*:\\s*"[^"]*' + requestId + '[^"]*"[^{}]*\\}', 'g'), new RegExp('\\{[^{}]*"response"[^{}]*"[^"]*"[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*\\}', 'g'),
// More flexible JSON patterns // More flexible JSON patterns - simplified
new RegExp('\\{[\\s\\S]*?"id"[\\s\\S]*?"' + requestId + '"[\\s\\S]*?"response"[\\s\\S]*?\\}', 'g'), new RegExp('\\{[\\s\\S]*?"id"[\\s\\S]*?"' + requestId + '"[\\s\\S]*?"response"[\\s\\S]*?\\}', 'g'),
new RegExp('\\{[\\s\\S]*?"response"[\\s\\S]*?"id"[\\s\\S]*?"' + requestId + '"[\\s\\S]*?\\}', 'g'), new RegExp('\\{[\\s\\S]*?"response"[\\s\\S]*?"id"[\\s\\S]*?"' + requestId + '"[\\s\\S]*?\\}', 'g')
// Very flexible patterns for malformed JSON
new RegExp('\\{[\\s\\S]*?["\']id["\']\\s*:\\s*["\'][^"\']*' + requestId + '[^"\']*["\'][\\s\\S]*?["\']response["\']\\s*:\\s*["\']([\\s\\S]*?)["\'][\\s\\S]*?\\}', 'g'),
new RegExp('\\{[\\s\\S]*?["\']response["\']\\s*:\\s*["\']([\\s\\S]*?)["\'][\\s\\S]*?["\']id["\']\\s*:\\s*["\'][^"\']*' + requestId + '[^"\']*["\'][\\s\\S]*?\\}', 'g')
]; ];
// Try both original and cleaned text // Try both original and cleaned text
...@@ -535,11 +532,11 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro ...@@ -535,11 +532,11 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro
.replace(/\\\\"/g, '\\"'); .replace(/\\\\"/g, '\\"');
// Try to extract just the response value if JSON parsing fails // Try to extract just the response value if JSON parsing fails
const responseMatch = fixedJson.match(/"response"\\s*:\\s*"([^"\\\\]|\\\\.)*"/); const responsePattern = /"response"\s*:\s*"([^"]*)"/;
const responseMatch = fixedJson.match(responsePattern);
if (responseMatch && fixedJson.includes(requestId)) { if (responseMatch && fixedJson.includes(requestId)) {
const valueMatch = responseMatch[0].match(/"response"\\s*:\\s*"(.*)"/); const responseValue = responseMatch[1];
if (valueMatch && valueMatch[1]) { if (responseValue) {
const responseValue = valueMatch[1];
console.log(`Extracted response from malformed JSON: ${responseValue.substring(0, 100)}...`); console.log(`Extracted response from malformed JSON: ${responseValue.substring(0, 100)}...`);
return responseValue; return responseValue;
} }
...@@ -738,7 +735,7 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro ...@@ -738,7 +735,7 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro
if (text && text.includes(requestId) && text.includes('{') && text.includes('"response"')) { if (text && text.includes(requestId) && text.includes('{') && text.includes('"response"')) {
console.log(`📄 Found element with potential JSON: ${text.substring(0, 150)}...`); console.log(`📄 Found element with potential JSON: ${text.substring(0, 150)}...`);
// Try to extract JSON from this text // Try to extract JSON from this text - simplified patterns
const jsonPattern1 = new RegExp('\\{[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*"response"[^{}]*\\}'); const jsonPattern1 = new RegExp('\\{[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*"response"[^{}]*\\}');
const jsonPattern2 = new RegExp('\\{[^{}]*"response"[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*\\}'); const jsonPattern2 = new RegExp('\\{[^{}]*"response"[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*\\}');
const jsonMatch = text.match(jsonPattern1) || text.match(jsonPattern2); const jsonMatch = text.match(jsonPattern1) || text.match(jsonPattern2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment