ktmud commented on code in PR #23908:
URL: https://github.com/apache/superset/pull/23908#discussion_r1184232222


##########
superset-frontend/src/SqlLab/actions/sqlLab.js:
##########
@@ -357,12 +357,70 @@ export function fetchQueryResults(query, displayLimit) {
   };
 }
 
+const quotes = '\'"`'.split('');
+const quotedBlockHash = shortid.generate();
+const quotedBlockMatch = new RegExp(`${quotedBlockHash}:\\d+:`, 'g');
+
+function splitByQuotedBlock(str) {
+  const chunks = [];
+  let currentQuote = '';
+  let chunkStart = 0;
+
+  let i = 0;
+  while (i < str.length) {
+    const currentChar = str[i];
+    if (
+      currentQuote ? currentChar === currentQuote : 
quotes.includes(currentChar)
+    ) {
+      let chunk;
+      if (currentQuote) {
+        chunk = str.substring(chunkStart, i + 1);
+        chunkStart = i + 1;
+        currentQuote = '';
+      } else {
+        chunk = str.substring(chunkStart, i);
+        chunkStart = i;
+        currentQuote = currentChar;
+      }
+      if (chunk) {
+        chunks.push(chunk);
+      }
+    }
+    i += 1;
+  }
+
+  if (chunkStart < str.length) {
+    const lastChunk = str.substring(chunkStart);
+    if (lastChunk) {
+      chunks.push(lastChunk);
+    }
+  }
+
+  return chunks;
+}
+
 export function cleanSqlComments(sql) {
   if (!sql) return '';
   // it sanitizes the following comment block groups
   // group 1 -> /* */
   // group 2 -> --
-  return sql.replace(/(--.*?$|\/\*[\s\S]*?\*\/)\n?/gm, '\n').trim();
+  const chunks = splitByQuotedBlock(sql);
+  return (
+    chunks
+      // replace quoted blocks in a hash format
+      .map((chunk, index) =>
+        quotes.includes(chunk[0]) ? `${quotedBlockHash}:${index}:` : chunk,
+      )
+      .join('')
+      // Clean out the commented-out blocks
+      .replace(/(--.*?$|\/\*[\s\S]*?\*\/)\n?/gm, '\n')

Review Comment:
   ```suggestion
         .replace(/(--.*$|\/\*[\s\S]*\*\/)\n?/gm, '\n')
   ```
   
   I don't think these question marks are necessary



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to