From b07649d05102f1478d54ce22f96e8cdb02dea6d3 Mon Sep 17 00:00:00 2001
From: piyush kumar sadangi
Date: Fri, 11 Oct 2024 07:28:19 +0530
Subject: [PATCH 1/2] Issue #141: Some config results in OOM, reduce list of
project in config
---
.../example/extractor/ConfigSerializer.java | 69 ++++++++++++++++++-
1 file changed, 67 insertions(+), 2 deletions(-)
diff --git a/extractor/src/main/java/com/example/extractor/ConfigSerializer.java b/extractor/src/main/java/com/example/extractor/ConfigSerializer.java
index e8e8c68cf..770fd98be 100644
--- a/extractor/src/main/java/com/example/extractor/ConfigSerializer.java
+++ b/extractor/src/main/java/com/example/extractor/ConfigSerializer.java
@@ -476,8 +476,73 @@ private static void appendProperty(final StringBuilder builder, final String ind
if (builder.length() > 0) {
builder.append('\n');
}
- builder.append(indent).append("");
+
+ // Check for quotes in the original, unescaped value
+ final boolean containsDoubleQuote = value.contains("\"");
+ final boolean containsSingleQuote = value.contains("'");
+
+ // Determine the appropriate quote character
+ final char quote;
+ if (containsDoubleQuote && !containsSingleQuote) {
+ // Use single quotes as delimiters
+ quote = '\'';
+ }
+ else {
+ // Use double quotes as delimiters in all other cases
+ quote = '"';
+ }
+
+ // Escape the value based on the selected quote character
+ final String escapedValue = escapeXmlAttributeValue(value, quote);
+
+ // Append the property to the builder
+ builder.append(indent)
+ .append("");
+ }
+
+ /**
+ * Escapes special XML characters in the input string.
+ * Replaces &, <, >, ", and ' with their corresponding XML entities.
+ * Returns the original input if null or empty.
+ *
+ * @param input the string to escape
+ * @return the escaped string or the original if null/empty
+ */
+ private static String escapeXml(final String input) {
+ String result = input;
+ if (input != null && !input.isEmpty()) {
+ result = input.replace("\"", """)
+ .replace("'", "'");
+ }
+ return result;
+ }
+
+ /**
+ * Escapes special characters in an XML attribute value.
+ * Replaces &, <, > with their corresponding XML entities.
+ * Depending on the delimiter, either ' or " is also escaped.
+ *
+ * @param input the string to escape
+ * @param delimiter the delimiter used for the attribute (' or ")
+ * @return the escaped string or the original if null/empty
+ */
+ private static String escapeXmlAttributeValue(final String input, final char delimiter) {
+ String result = input;
+ if (input != null && !input.isEmpty()) {
+ if (delimiter == '\'') {
+ result = result.replace("'", "'");
+ }
+ else {
+ result = result.replace("\"", """);
+ }
+ }
+ return result;
}
/**
From 6400987c8e15bc4ac8dfa41269caefb0bd6f7a54 Mon Sep 17 00:00:00 2001
From: piyush kumar sadangi
Date: Fri, 11 Oct 2024 07:28:28 +0530
Subject: [PATCH 2/2] Changes
---
IllegalTokenText/Example3/config.xml | 2 +-
IllegalTokenText/all-examples-in-one/config.xml | 2 +-
MultipleStringLiterals/Example3/config.xml | 2 +-
MultipleStringLiterals/all-examples-in-one/config.xml | 2 +-
Regexp/Example12/config.xml | 2 +-
Regexp/Example13/config.xml | 2 +-
Regexp/all-examples-in-one/config.xml | 4 ++--
7 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/IllegalTokenText/Example3/config.xml b/IllegalTokenText/Example3/config.xml
index 1d81b2a6c..6cb71c37b 100644
--- a/IllegalTokenText/Example3/config.xml
+++ b/IllegalTokenText/Example3/config.xml
@@ -23,7 +23,7 @@
-
+
diff --git a/IllegalTokenText/all-examples-in-one/config.xml b/IllegalTokenText/all-examples-in-one/config.xml
index d750aea2a..0bfbb6c07 100644
--- a/IllegalTokenText/all-examples-in-one/config.xml
+++ b/IllegalTokenText/all-examples-in-one/config.xml
@@ -36,7 +36,7 @@
-
+
diff --git a/MultipleStringLiterals/Example3/config.xml b/MultipleStringLiterals/Example3/config.xml
index 620ce087b..b90a3ea3f 100644
--- a/MultipleStringLiterals/Example3/config.xml
+++ b/MultipleStringLiterals/Example3/config.xml
@@ -23,7 +23,7 @@
-
+
diff --git a/MultipleStringLiterals/all-examples-in-one/config.xml b/MultipleStringLiterals/all-examples-in-one/config.xml
index 741a0b702..27fe1a3b5 100644
--- a/MultipleStringLiterals/all-examples-in-one/config.xml
+++ b/MultipleStringLiterals/all-examples-in-one/config.xml
@@ -33,7 +33,7 @@
-
+
diff --git a/Regexp/Example12/config.xml b/Regexp/Example12/config.xml
index 0a0e01215..1d6823de5 100644
--- a/Regexp/Example12/config.xml
+++ b/Regexp/Example12/config.xml
@@ -23,7 +23,7 @@
-
+
diff --git a/Regexp/Example13/config.xml b/Regexp/Example13/config.xml
index b1d1c1f78..ead2954cb 100644
--- a/Regexp/Example13/config.xml
+++ b/Regexp/Example13/config.xml
@@ -24,7 +24,7 @@
- \)\. You shall not\n \* disclose such Confidential Information and shall use it only in\n \* accordance with the terms of the license agreement you entered into\n \* with ACME\.\n \*
\n \*\n \* © copyright \d\d\d\d ACME\n \*\n \* @author .*)(\n\s\*.*)*/\n[\w|\s]*( class | interface )"/>
+
diff --git a/Regexp/all-examples-in-one/config.xml b/Regexp/all-examples-in-one/config.xml
index 1affd6c40..551ba5702 100644
--- a/Regexp/all-examples-in-one/config.xml
+++ b/Regexp/all-examples-in-one/config.xml
@@ -88,14 +88,14 @@
-
+
- \)\. You shall not\n \* disclose such Confidential Information and shall use it only in\n \* accordance with the terms of the license agreement you entered into\n \* with ACME\.\n \* \n \*\n \* © copyright \d\d\d\d ACME\n \*\n \* @author .*)(\n\s\*.*)*/\n[\w|\s]*( class | interface )"/>
+