@stackql/provider-utils 0.4.9 → 0.5.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackql/provider-utils",
3
- "version": "0.4.9",
3
+ "version": "0.5.0",
4
4
  "description": "Utilities for building StackQL providers from OpenAPI specifications.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -28,21 +28,69 @@ export function getIndefiniteArticle(resourceName) {
28
28
  * @param {string} text - The text to sanitize
29
29
  * @return {string} - The sanitized text
30
30
  */
31
+ // export function sanitizeHtml(text) {
32
+ // if (!text) return '';
33
+
34
+ // // Special handling for code tags - temporarily replace them with placeholders
35
+ // // that won't get escaped in the general sanitization
36
+ // let result = text
37
+ // // Replace <code> tags with a safe placeholder
38
+ // .replace(/<code>/g, '___CODE_OPEN___')
39
+ // .replace(/<\/code>/g, '___CODE_CLOSE___');
40
+
41
+ // // Remove <nobr> tags completely
42
+ // result = result
43
+ // .replace(/<nobr>/g, '')
44
+ // .replace(/<\/nobr>/g, '');
45
+
46
+ // // Then apply the general sanitization
47
+ // result = result
48
+ // .replace(/{/g, '&#123;')
49
+ // .replace(/}/g, '&#125;')
50
+ // .replace(/>/g, '&gt;')
51
+ // .replace(/</g, '&lt;')
52
+ // // edge case
53
+ // .replace(/&#125;_&#123;/g, '&#125;&#95;&#123;')
54
+ // .replace(/\n/g, '<br />');
55
+
56
+ // // Fix 1: Replace &lt;br&gt;, &lt;br/&gt;, &lt;p&gt;, &lt;/p&gt; back to their literal HTML tags
57
+ // // Make sure <br> is always self-closing for MDX compatibility
58
+ // result = result
59
+ // .replace(/&lt;br\s*\/?&gt;/gi, '<br />')
60
+ // .replace(/&lt;p&gt;/gi, '<p>')
61
+ // .replace(/&lt;\/p&gt;/gi, '</p>');
62
+
63
+ // // Fix 2: Find any &lt; or &gt; inside backticks and convert them back to < and >
64
+ // // We need to handle the backtick content by finding pairs of backticks
65
+ // result = result.replace(/`([^`]*)`/g, (match, content) => {
66
+ // // Convert &lt; and &gt; back to < and > only within backticked content
67
+ // const fixedContent = content
68
+ // .replace(/&lt;/g, '<')
69
+ // .replace(/&gt;/g, '>');
70
+ // return '`' + fixedContent + '`';
71
+ // });
72
+
73
+ // // Finally, restore the code tags
74
+ // result = result
75
+ // .replace(/___CODE_OPEN___/g, '<code>')
76
+ // .replace(/___CODE_CLOSE___/g, '</code>');
77
+
78
+ // return result;
79
+ // }
31
80
  export function sanitizeHtml(text) {
32
81
  if (!text) return '';
33
82
 
34
83
  // Special handling for code tags - temporarily replace them with placeholders
35
- // that won't get escaped in the general sanitization
36
84
  let result = text
37
85
  // Replace <code> tags with a safe placeholder
38
86
  .replace(/<code>/g, '___CODE_OPEN___')
39
87
  .replace(/<\/code>/g, '___CODE_CLOSE___');
40
-
41
- // Remove <nobr> tags completely
88
+
89
+ // Remove <nobr> tags completely
42
90
  result = result
43
91
  .replace(/<nobr>/g, '')
44
92
  .replace(/<\/nobr>/g, '');
45
-
93
+
46
94
  // Then apply the general sanitization
47
95
  result = result
48
96
  .replace(/{/g, '&#123;')
@@ -51,17 +99,18 @@ export function sanitizeHtml(text) {
51
99
  .replace(/</g, '&lt;')
52
100
  // edge case
53
101
  .replace(/&#125;_&#123;/g, '&#125;&#95;&#123;')
102
+ // Handle all types of line breaks - very important!
103
+ .replace(/\r\n/g, '<br />')
104
+ .replace(/\r/g, '<br />')
54
105
  .replace(/\n/g, '<br />');
55
106
 
56
107
  // Fix 1: Replace &lt;br&gt;, &lt;br/&gt;, &lt;p&gt;, &lt;/p&gt; back to their literal HTML tags
57
- // Make sure <br> is always self-closing for MDX compatibility
58
108
  result = result
59
109
  .replace(/&lt;br\s*\/?&gt;/gi, '<br />')
60
110
  .replace(/&lt;p&gt;/gi, '<p>')
61
111
  .replace(/&lt;\/p&gt;/gi, '</p>');
62
112
 
63
- // Fix 2: Find any &lt; or &gt; inside backticks and convert them back to < and >
64
- // We need to handle the backtick content by finding pairs of backticks
113
+ // Fix 2: Handle backticked content more carefully
65
114
  result = result.replace(/`([^`]*)`/g, (match, content) => {
66
115
  // Convert &lt; and &gt; back to < and > only within backticked content
67
116
  const fixedContent = content
@@ -70,11 +119,16 @@ export function sanitizeHtml(text) {
70
119
  return '`' + fixedContent + '`';
71
120
  });
72
121
 
122
+ // IMPORTANT: Explicitly sanitize any <location> tags that might be in the text
123
+ // This ensures they get properly escaped even if added later
124
+ result = result.replace(/<location>/g, '&lt;location&gt;')
125
+ .replace(/<\/location>/g, '&lt;/location&gt;');
126
+
73
127
  // Finally, restore the code tags
74
128
  result = result
75
129
  .replace(/___CODE_OPEN___/g, '<code>')
76
130
  .replace(/___CODE_CLOSE___/g, '</code>');
77
-
131
+
78
132
  return result;
79
133
  }
80
134