You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2021/10/13 09:59:31 UTC

[GitHub] [netbeans] ppisl commented on a change in pull request #3242: [NETBEANS-6086] YAML Parser Changes (fix: OOME)

ppisl commented on a change in pull request #3242:
URL: https://github.com/apache/netbeans/pull/3242#discussion_r727899495



##########
File path: ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlParser.java
##########
@@ -112,68 +98,56 @@ private YamlParserResult resultForTooLargeFile(Snapshot snapshot) {
     }
 
     // package private for unit tests
-    static String replacePhpFragments(String source) {
-        // this is a hack. The right solution would be to create a toplevel language, which
-        // will have embeded yaml and php.
-        // This code replaces php fragments with space, because jruby parser fails
-        // on this.
-        int startReplace = source.indexOf("<?");
+    static void replaceWithSpaces(StringBuilder source, String startToken, String endToken) {
+        int startReplace = source.indexOf(startToken);
         if (startReplace == -1) {
-            return source;
+            return;
         }
 
-        StringBuilder result = new StringBuilder(source);
-
         while (startReplace > -1) {
-            int endReplace = result.indexOf("?>", startReplace);
-            if (endReplace > -1) {
-                endReplace = endReplace + 1;
-                StringBuilder spaces = new StringBuilder(endReplace - startReplace);
-                for (int i = 0; i <= endReplace - startReplace; i++) {
-                    spaces.append(' ');
+            int endReplace = source.indexOf(endToken, startReplace) + 1;
+            if (endReplace > startReplace) {
+                for (int i = startReplace; i <= endReplace; i++) {
+                    source.setCharAt(i, ' ');
                 }
-                result.replace(startReplace, endReplace + 1, spaces.toString());
-                startReplace = result.indexOf("<?", endReplace);
+                startReplace = source.indexOf(startToken, endReplace);
             } else {
                 startReplace = -1;
             }
         }
-        return result.toString();
+    }
+    
+    static void replacePhpFragments(StringBuilder source) {
+        // this is a hack. The right solution would be to create a toplevel language, which
+        // will have embeded yaml and php.
+        // This code replaces php fragments with space, because jruby parser fails
+        // on this.
+        replaceWithSpaces(source, "<?", "?>");

Review comment:
       I'm not sure, it will handle correctly cases like this:
   ```somekey: "<?php echo '<?php echo 1; ?>'; ?>"```
   
   My guess is that ti will produce code like:
   ```somekey: "                                                 '; ?>"
   which probalbly the parser will not be able to parse




-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists