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
// Clean the text first
const cleanedText = cleanJsonText(text);
// Look for JSON patterns with our unique ID
// Look for JSON patterns with our unique ID - simplified patterns
const jsonPatterns = [
// Standard JSON object patterns
new RegExp('\\{[^{}]*"id"\\s*:\\s*"[^"]*' + requestId + '[^"]*"[^{}]*"response"\\s*:\\s*"([^"\\\\]|\\\\.)*"[^{}]*\\}', 'g'),
new RegExp('\\{[^{}]*"response"\\s*:\\s*"([^"\\\\]|\\\\.)*"[^{}]*"id"\\s*:\\s*"[^"]*' + requestId + '[^"]*"[^{}]*\\}', 'g'),
// More flexible JSON patterns
// Standard JSON object patterns - simplified
new RegExp('\\{[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*"response"[^{}]*"[^"]*"[^{}]*\\}', 'g'),
new RegExp('\\{[^{}]*"response"[^{}]*"[^"]*"[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*\\}', 'g'),
// More flexible JSON patterns - simplified
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'),
// 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')
new RegExp('\\{[\\s\\S]*?"response"[\\s\\S]*?"id"[\\s\\S]*?"' + requestId + '"[\\s\\S]*?\\}', 'g')
];
// Try both original and cleaned text
......@@ -535,11 +532,11 @@ async def detect_json_response_with_id(page, container_selector, request_id, pro
.replace(/\\\\"/g, '\\"');
// 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)) {
const valueMatch = responseMatch[0].match(/"response"\\s*:\\s*"(.*)"/);
if (valueMatch && valueMatch[1]) {
const responseValue = valueMatch[1];
const responseValue = responseMatch[1];
if (responseValue) {
console.log(`Extracted response from malformed JSON: ${responseValue.substring(0, 100)}...`);
return responseValue;
}
......@@ -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"')) {
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 jsonPattern2 = new RegExp('\\{[^{}]*"response"[^{}]*"id"[^{}]*"' + requestId + '"[^{}]*\\}');
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