funda-ui 4.7.604 → 4.7.608

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2522,10 +2522,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2522
2522
  __nested_webpack_require_993__.r(__webpack_exports__);
2523
2523
  /* harmony export */
2524
2524
  __nested_webpack_require_993__.d(__webpack_exports__, {
2525
- /* harmony export */"fixAndParseJSON": function fixAndParseJSON() {
2526
- return (/* binding */_fixAndParseJSON
2527
- );
2528
- },
2529
2525
  /* harmony export */"isEmail": function isEmail() {
2530
2526
  return (/* binding */_isEmail
2531
2527
  );
@@ -2571,63 +2567,82 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2571
2567
  }
2572
2568
  /**
2573
2569
  * Fix And Parse JSON (Support for handling complex escape JSON strings)
2570
+ * @desc recursively fix top-level key/value (recursively handles when encountering top-level values that are objects/arrays)
2574
2571
  * @private
2575
2572
  */
2576
2573
  /*
2577
- - Always try JSON.parse first;
2578
- - If parsing fails, unescape \" → ";
2579
- - Then process the outermost object or array key-by-key, value-by-value;
2580
- - If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
2581
- recursively treat that value as a new root to repair;
2582
- - For values wrapped in quotes ('...' or "..."), extract the inner text and
2583
- re-encode it using JSON.stringify (ensures internal single/double quotes
2584
- are not corrupted);
2574
+ - Still prioritize JSON.parse first;
2575
+ - After parse fails, do unescaping (\\" → ");
2576
+ - Then process the outermost layer (object or array) key by key, value by value;
2577
+ - If a top-level value is an unquoted object or array (e.g., messages: [ {...} ]), recursively treat that value as a new outermost layer for fixing;
2578
+ - For strings wrapped in quotes ('...' or "..."), only extract the outer layer and re-encode with JSON.stringify (ensuring internal single/double quotes won't be mistakenly changed);
2585
2579
  - Set MAX_DEPTH to prevent infinite recursion.
2586
2580
  */
2587
- // fixAndParseJSON - recursively repairs top-level key/value
2588
- // (when encountering outermost values that are objects/arrays, it recurses)
2589
-
2590
2581
  /*
2591
- DEMO:
2582
+ @Examples:
2592
2583
 
2593
- // ✅ Valid JSON (contains svg and single-quote content)
2584
+ // ✅ Valid JSON (contains svg and single quote content)
2594
2585
  const okJson = `{
2595
- "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
2586
+ "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> 新建会话",
2596
2587
  "value":"new",
2597
2588
  "onClick":"method.setVal(''); method.clearData();"
2598
2589
  }`;
2599
2590
 
2600
- // Single-quote JSON
2591
+ const okJson2 = `{
2592
+ label:"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> 新建会话",
2593
+ value:"new",
2594
+ onClick:"method.setVal(''); method.clearData();"
2595
+ }`;
2596
+
2597
+ // ⚠️ Single quote JSON
2601
2598
  const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
2602
2599
 
2603
- // Escaped JSON
2604
- const badJson2 = "{\\\"label\\\":\\\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\\\",\\\"value\\\":\\\"new\\\",\\\"onClick\\\":\\\"method.setVal(''); method.clearData();\\\"}";
2600
+ // ⚠️ Escaped JSON
2601
+ const badJson2 = "{\\\"label\\\":\\\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> 新建会话\\\",\\\"value\\\":\\\"new\\\",\\\"onClick\\\":\\\"method.setVal(''); method.clearData();\\\"}";
2602
+
2603
+ const badJson3 = "{\"label\":\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> 新建会话\",\"value\":\"new\",\"onClick\":\"method.setVal(''); method.clearData();\"}";
2604
+
2605
+ const badJson4 = "[{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M20.5 9a3.49 3.49 0 0 0-3.45 3h-1.1a2.49 2.49 0 0 0-4.396-1.052L8.878 9.731l3.143-4.225a2.458 2.458 0 0 0 2.98-.019L17.339 8H16v1h3V6h-1v1.243l-2.336-2.512A2.473 2.473 0 0 0 16 3.5a2.5 2.5 0 0 0-5 0 2.474 2.474 0 0 0 .343 1.243L7.947 9.308 4.955 7.947a2.404 2.404 0 0 0-.161-1.438l3.704-1.385-.44 1.371.942.333L10 4 7.172 3l-.334.943 1.01.357-3.659 1.368a2.498 2.498 0 1 0-.682 4.117l2.085 2.688-2.053 2.76a2.5 2.5 0 1 0 .87 3.864l3.484 1.587-1.055.373.334.943L10 21l-1-2.828-.943.333.435 1.354-3.608-1.645A2.471 2.471 0 0 0 5 17.5a2.5 2.5 0 0 0-.058-.527l3.053-1.405 3.476 4.48a2.498 2.498 0 1 0 4.113.075L18 17.707V19h1v-3h-3v1h1.293l-2.416 2.416a2.466 2.466 0 0 0-2.667-.047l-3.283-4.23 2.554-1.176A2.494 2.494 0 0 0 15.95 13h1.1a3.493 3.493 0 1 0 3.45-4zm-7-7A1.5 1.5 0 1 1 12 3.5 1.502 1.502 0 0 1 13.5 2zm0 18a1.5 1.5 0 1 1-1.5 1.5 1.502 1.502 0 0 1 1.5-1.5zM1 7.5a1.5 1.5 0 1 1 2.457 1.145l-.144.112A1.496 1.496 0 0 1 1 7.5zm3.32 1.703a2.507 2.507 0 0 0 .264-.326l2.752 1.251-1.124 1.512zM2.5 19A1.5 1.5 0 1 1 4 17.5 1.502 1.502 0 0 1 2.5 19zm2.037-2.941a2.518 2.518 0 0 0-.193-.234l1.885-2.532 1.136 1.464zm3.76-1.731L6.849 12.46l1.42-1.908L11.1 11.84a2.29 2.29 0 0 0-.033 1.213zM13.5 14a1.5 1.5 0 1 1 1.5-1.5 1.502 1.502 0 0 1-1.5 1.5zm7 1a2.5 2.5 0 1 1 2.5-2.5 2.502 2.502 0 0 1-2.5 2.5zm1.5-2.5a1.5 1.5 0 1 1-1.5-1.5 1.502 1.502 0 0 1 1.5 1.5z'/><path fill='none' d='M0 0h24v24H0z'/></svg> 深度思考\",\"value\":\"brief\",\"onClick\":\"if(isActive){method.executeCustomMethod('changeModel', true)}else{method.executeCustomMethod('changeModel', false)}\"},{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M19 2H5c-1.103 0-2 .897-2 2v12c0 1.103.897 2 2 2h3.586L12 21.414 15.414 18H19c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zm0 14h-4.414L12 18.586 9.414 16H5V4h14v12z'/></svg> 精简回答\",\"value\":\"brief\",\"onClick\":\"if(isActive){method.setContextData({systemPrompt:'请精简回答,字数控制在150个字左右, 思考过程请简洁简短',mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}else{method.setContextData({mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}\"},{\"label\":\"<svg fill='none' width='12' height='12' viewBox='0 0 16 16'><path d='M7 0.0618896V9H15.9381C15.446 12.9463 12.0796 16 8 16C3.58172 16 0 12.4183 0 8C0 3.92038 3.05369 0.553988 7 0.0618896Z' fill='currentColor'/><path d='M9 0.0618897V7H15.9381C15.4869 3.38128 12.6187 0.513137 9 0.0618897Z' fill='currentColor'/></svg> 指标分析\",\"value\":\"lab\",\"onClick\":\"return method.executeCustomMethod('getLibList')\",\"isSelect\":true,\"dynamicOptions\":true}]";
2606
+
2605
2607
 
2606
- const badJson3 = "{\"label\":\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\",\"value\":\"new\",\"onClick\":\"method.setVal(''); method.clearData();\"}";
2608
+ // Invalid JSON with missing } or ]
2609
+ const errorJson001 = "{'model':'qwen-plus','base_url':'https://dashscope.aliyuncs.com/compatible-mode/v1/','api_key':'sk-0989fb9baab8450682af4d000f5b7cba','message':'{message}','stream':'true','chatId': '{chatId}', 'token': '{token}'";
2607
2610
 
2608
- const badJson4 = "[{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M20.5 9a3.49 3.49 0 0 0-3.45 3h-1.1a2.49 2.49 0 0 0-4.396-1.052L8.878 9.731l3.143-4.225a2.458 2.458 0 0 0 2.98-.019L17.339 8H16v1h3V6h-1v1.243l-2.336-2.512A2.473 2.473 0 0 0 16 3.5a2.5 2.5 0 0 0-5 0 2.474 2.474 0 0 0 .343 1.243L7.947 9.308 4.955 7.947a2.404 2.404 0 0 0-.161-1.438l3.704-1.385-.44 1.371.942.333L10 4 7.172 3l-.334.943 1.01.357-3.659 1.368a2.498 2.498 0 1 0-.682 4.117l2.085 2.688-2.053 2.76a2.5 2.5 0 1 0 .87 3.864l3.484 1.587-1.055.373.334.943L10 21l-1-2.828-.943.333.435 1.354-3.608-1.645A2.471 2.471 0 0 0 5 17.5a2.5 2.5 0 0 0-.058-.527l3.053-1.405 3.476 4.48a2.498 2.498 0 1 0 4.113.075L18 17.707V19h1v-3h-3v1h1.293l-2.416 2.416a2.466 2.466 0 0 0-2.667-.047l-3.283-4.23 2.554-1.176A2.494 2.494 0 0 0 15.95 13h1.1a3.493 3.493 0 1 0 3.45-4zm-7-7A1.5 1.5 0 1 1 12 3.5 1.502 1.502 0 0 1 13.5 2zm0 18a1.5 1.5 0 1 1-1.5 1.5 1.502 1.502 0 0 1 1.5-1.5zM1 7.5a1.5 1.5 0 1 1 2.457 1.145l-.144.112A1.496 1.496 0 0 1 1 7.5zm3.32 1.703a2.507 2.507 0 0 0 .264-.326l2.752 1.251-1.124 1.512zM2.5 19A1.5 1.5 0 1 1 4 17.5 1.502 1.502 0 0 1 2.5 19zm2.037-2.941a2.518 2.518 0 0 0-.193-.234l1.885-2.532 1.136 1.464zm3.76-1.731L6.849 12.46l1.42-1.908L11.1 11.84a2.29 2.29 0 0 0-.033 1.213zM13.5 14a1.5 1.5 0 1 1 1.5-1.5 1.502 1.502 0 0 1-1.5 1.5zm7 1a2.5 2.5 0 1 1 2.5-2.5 2.502 2.502 0 0 1-2.5 2.5zm1.5-2.5a1.5 1.5 0 1 1-1.5-1.5 1.502 1.502 0 0 1 1.5 1.5z'/><path fill='none' d='M0 0h24v24H0z'/></svg> Deep Thought","value":"brief","onClick":"if(isActive){method.executeCustomMethod('changeModel', true)}else{method.executeCustomMethod('changeModel', false)}"},{"label":"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M19 2H5c-1.103 0-2 .897-2 2v12c0 1.103.897 2 2 2h3.586L12 21.414 15.414 18H19c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zm0 14h-4.414L12 18.586 9.414 16H5V4h14v12z'/></svg> Concise Answer","value":"brief","onClick":"if(isActive){method.setContextData({systemPrompt:'Please answer concisely, around 150 words, keep reasoning brief',mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}else{method.setContextData({mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}"},{"label":"<svg fill='none' width='12' height='12' viewBox='0 0 16 16'><path d='M7 0.0618896V9H15.9381C15.446 12.9463 12.0796 16 8 16C3.58172 16 0 12.4183 0 8C0 3.92038 3.05369 0.553988 7 0.0618896Z' fill='currentColor'/><path d='M9 0.0618897V7H15.9381C15.4869 3.38128 12.6187 0.513137 9 0.0618897Z' fill='currentColor'/></svg> Metrics Analysis","value":"lab","onClick":"return method.executeCustomMethod('getLibList')","isSelect":true,"dynamicOptions":true}]";
2611
+ const errorJson002 = "[{'model':'qwen-plus','base_url':'https://dashscope.aliyuncs.com/compatible-mode/v1/','api_key':'sk-0989fb9baab8450682af4d000f5b7cba','message':'{message}','stream':'true','chatId': '{chatId}', 'token': '{token}'}";
2609
2612
 
2613
+ // ❌ Invalid JSON with missing quotes
2614
+ const errorJson003 = "{'model':'qwen-plus','base_url':'https://dashscope.aliyuncs.com/compatible-mode/v1/','api_key':'sk-0989fb9baab8450682af4d000f5b7cba','message':'{message}','stream':'true','chatId': {chatId}', 'token': '{token}'}";
2615
+
2616
+
2617
+
2618
+ console.log('okJson =>', fixAndParseJSON(okJson)); // Can parse normally success = true
2619
+ console.log('okJson =>', fixAndParseJSON(okJson2)); // Can parse normally success = true
2620
+ console.log('badJson =>', fixAndParseJSON(badJson)); // Can parse after fixing success = true
2621
+ console.log('badJson =>', fixAndParseJSON(badJson2)); // Can parse after fixing success = true
2622
+ console.log('badJson =>', fixAndParseJSON(badJson3)); // Can parse after fixing success = true
2623
+ console.log('badJson =>', fixAndParseJSON(badJson4)); // Can parse after fixing success = true
2624
+ console.log('errorJson =>', fixAndParseJSON(errorJson001)); // {success: false, error: 'Invalid JSON format', details: 'Invalid object: mismatched braces'}
2625
+ console.log('errorJson =>', fixAndParseJSON(errorJson002)); // {success: false, error: 'Invalid JSON format', details: "Expected property name or '}' in JSON at position 2 (line 1 column 3)"}
2626
+ console.log('errorJson =>', fixAndParseJSON(errorJson003)); // {success: false, error: 'Invalid JSON format', details: 'Invalid object: mismatched braces'}
2610
2627
 
2611
- console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
2612
- console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
2613
- console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
2614
- console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
2615
- console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
2616
2628
  */
2617
- function _fixAndParseJSON(input) {
2629
+
2630
+ // Type definitions
2631
+
2632
+ function fixAndParseJSON(input) {
2618
2633
  var MAX_DEPTH = 6;
2619
2634
 
2620
- // 1. Fast attempt
2635
+ // 1. Quick attempt
2621
2636
  try {
2622
2637
  return {
2623
2638
  success: true,
2624
2639
  data: JSON.parse(input)
2625
2640
  };
2626
2641
  } catch (e) {
2627
- // continue to repair
2642
+ // Continue with fixing
2628
2643
  }
2629
2644
 
2630
- // 2. Simple unescape of \" (common when copied from JS literals)
2645
+ // 2. Simple unescaping of escaped \" (common case from pasted JS literals)
2631
2646
  var s = input;
2632
2647
  if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
2633
2648
  s = s.trim();
@@ -2644,24 +2659,54 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2644
2659
  data: JSON.parse(s)
2645
2660
  };
2646
2661
  } catch (err) {
2662
+ var error = err instanceof Error ? err : new Error('Unknown error');
2647
2663
  return {
2648
2664
  success: false,
2649
2665
  error: 'Invalid JSON format',
2650
- details: err instanceof Error ? err.message : String(err)
2666
+ details: error.message
2651
2667
  };
2652
2668
  }
2653
2669
  }
2654
2670
 
2655
- /* ---------- Helper (recursive) functions ---------- */
2671
+ /* ---------- Helper (Recursive) Functions ---------- */
2656
2672
 
2657
2673
  function processTopObject(str, depth, MAX_DEPTH) {
2658
2674
  if (depth > MAX_DEPTH) return str;
2659
2675
  str = str.trim();
2660
- // Ensure it is wrapped in { ... }
2676
+
2677
+ // First check if braces match
2678
+ var braceCount = 0;
2679
+ var inString = false;
2680
+ var escapeNext = false;
2681
+ for (var i = 0; i < str.length; i++) {
2682
+ var ch = str[i];
2683
+ if (escapeNext) {
2684
+ escapeNext = false;
2685
+ continue;
2686
+ }
2687
+ if (ch === '\\') {
2688
+ escapeNext = true;
2689
+ continue;
2690
+ }
2691
+ if ((ch === '"' || ch === "'") && !escapeNext) {
2692
+ inString = !inString;
2693
+ continue;
2694
+ }
2695
+ if (!inString) {
2696
+ if (ch === '{') braceCount++;else if (ch === '}') braceCount--;
2697
+ }
2698
+ }
2699
+ if (braceCount !== 0) {
2700
+ throw new Error('Invalid object: mismatched braces');
2701
+ }
2702
+
2703
+ // Ensure both ends are { ... }
2661
2704
  if (!(str.startsWith('{') && str.endsWith('}'))) {
2662
- var f = str.indexOf('{');
2663
- var l = str.lastIndexOf('}');
2664
- if (f === -1 || l === -1 || l <= f) return str;
2705
+ var f = str.indexOf('{'),
2706
+ l = str.lastIndexOf('}');
2707
+ if (f === -1 || l === -1 || l <= f) {
2708
+ throw new Error('Invalid object format: missing or mismatched braces');
2709
+ }
2665
2710
  str = str.slice(f, l + 1);
2666
2711
  }
2667
2712
  var inner = str.slice(1, -1);
@@ -2686,8 +2731,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2686
2731
  if (depth > MAX_DEPTH) return str;
2687
2732
  str = str.trim();
2688
2733
  if (!(str.startsWith('[') && str.endsWith(']'))) {
2689
- var f = str.indexOf('[');
2690
- var l = str.lastIndexOf(']');
2734
+ var f = str.indexOf('['),
2735
+ l = str.lastIndexOf(']');
2691
2736
  if (f === -1 || l === -1 || l <= f) return str;
2692
2737
  str = str.slice(f, l + 1);
2693
2738
  }
@@ -2703,21 +2748,21 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2703
2748
  return '[' + processed.join(',') + ']';
2704
2749
  }
2705
2750
 
2706
- // If value is quoted, extract inside and JSON.stringify again (safe escaping)
2707
- // If value is unquoted object/array literal, recurse treating it as new root
2708
- // Otherwise return as is (numbers, booleans, null, or raw expressions)
2751
+ // If it's a string wrapped in quotes, extract the inner content and JSON.stringify (safe escaping)
2752
+ // If it's an object/array literal (not wrapped in quotes), recursively process (treat as new outermost layer)
2753
+ // Otherwise return the original fragment directly (numbers/true/false/null or JS expressions)
2709
2754
  function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
2710
2755
  var v = rawVal.trim();
2711
2756
  if (v === '') return v;
2712
2757
  if (v[0] === '"' || v[0] === "'") {
2713
2758
  var quote = v[0];
2714
- // Find the last unescaped matching quote
2759
+ // Find the last unescaped same quote
2715
2760
  var lastPos = -1;
2716
2761
  for (var i = v.length - 1; i >= 0; i--) {
2717
2762
  if (v[i] === quote) {
2718
- // check if escaped
2719
- var bs = 0;
2720
- var k = i - 1;
2763
+ // check escaped
2764
+ var bs = 0,
2765
+ k = i - 1;
2721
2766
  while (k >= 0 && v[k] === '\\') {
2722
2767
  bs++;
2723
2768
  k--;
@@ -2729,10 +2774,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2729
2774
  }
2730
2775
  }
2731
2776
  var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
2732
- return JSON.stringify(inner); // Generate valid JSON string (auto escape)
2777
+ return JSON.stringify(inner); // Use JSON.stringify to generate valid JSON string (automatically escape internal quotes, etc.)
2733
2778
  }
2734
2779
 
2735
- // If unquoted object/array literal -> recurse
2780
+ // If it's an object or array literal (not wrapped in quotes) -> recursively treat as new outermost layer
2736
2781
  if (v.startsWith('{')) {
2737
2782
  return processTopObject(v, depth, MAX_DEPTH);
2738
2783
  }
@@ -2740,22 +2785,22 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2740
2785
  return processTopArray(v, depth, MAX_DEPTH);
2741
2786
  }
2742
2787
 
2743
- // Other (number, boolean, null, raw expression): return as is
2788
+ // Others (numbers, boolean, null, or JS expressions): return as-is
2744
2789
  return v;
2745
2790
  }
2746
2791
 
2747
- /* --------- Utils: split by top-level commas, find colon, extract key --------- */
2792
+ /* --------- Utilities: Split by top-level commas, find top-level colon, extract key --------- */
2748
2793
 
2749
- // Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
2794
+ // Split by top-level commas (ignore strings, sub-objects, sub-arrays, commas inside parentheses)
2750
2795
  function splitTopLevel(str) {
2751
2796
  var parts = [];
2752
2797
  var buf = '';
2753
- var depthCurly = 0;
2754
- var depthSquare = 0;
2755
- var depthParen = 0;
2756
- var inSingle = false;
2757
- var inDouble = false;
2758
- var esc = false;
2798
+ var depthCurly = 0,
2799
+ depthSquare = 0,
2800
+ depthParen = 0;
2801
+ var inSingle = false,
2802
+ inDouble = false,
2803
+ esc = false;
2759
2804
  for (var i = 0; i < str.length; i++) {
2760
2805
  var ch = str[i];
2761
2806
  if (esc) {
@@ -2817,18 +2862,23 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2817
2862
  }
2818
2863
  buf += ch;
2819
2864
  }
2865
+
2866
+ // Check for unclosed brackets or quotes
2867
+ if (depthCurly !== 0 || depthSquare !== 0 || depthParen !== 0 || inSingle || inDouble) {
2868
+ throw new Error('Invalid JSON: unclosed brackets or quotes');
2869
+ }
2820
2870
  if (buf.trim() !== '') parts.push(buf);
2821
2871
  return parts;
2822
2872
  }
2823
2873
 
2824
- // Find the first top-level colon (ignores strings and nested structures)
2874
+ // Find the first "top-level" colon index (ignore inside strings & sub-levels)
2825
2875
  function findTopLevelColon(str) {
2826
- var inSingle = false;
2827
- var inDouble = false;
2828
- var esc = false;
2829
- var depthCurly = 0;
2830
- var depthSquare = 0;
2831
- var depthParen = 0;
2876
+ var inSingle = false,
2877
+ inDouble = false,
2878
+ esc = false;
2879
+ var depthCurly = 0,
2880
+ depthSquare = 0,
2881
+ depthParen = 0;
2832
2882
  for (var i = 0; i < str.length; i++) {
2833
2883
  var ch = str[i];
2834
2884
  if (esc) {
@@ -2880,7 +2930,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2880
2930
  return -1;
2881
2931
  }
2882
2932
 
2883
- // Extract key content (supports "key", 'key', key) returns pure string key
2933
+ // Extract key content (supports "key", 'key', key), returns pure key string
2884
2934
  function extractKeyContent(rawKey) {
2885
2935
  var r = rawKey.trim();
2886
2936
  if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
@@ -2896,7 +2946,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2896
2946
  */
2897
2947
  function _isJSON(input) {
2898
2948
  if (typeof input === 'string' && input.length > 0) {
2899
- return _fixAndParseJSON(input).success;
2949
+ return fixAndParseJSON(input).success;
2900
2950
  } else {
2901
2951
  if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
2902
2952
  return true;