Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some config results in OOM, reduce list of project in config #212

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion IllegalTokenText/Example3/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<property name="javaParseExceptionSeverity" value="ignore"/>

<module name="IllegalTokenText">
<property name="format" value="""/>
<property name="format" value='"'/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<property name="tokens" value="TEXT_BLOCK_CONTENT"/>
</module>

Expand Down
2 changes: 1 addition & 1 deletion IllegalTokenText/all-examples-in-one/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</module>

<module name="IllegalTokenText">
<property name="format" value="""/>
<property name="format" value='"'/>
<property name="id" value="example3"/>
<property name="tokens" value="TEXT_BLOCK_CONTENT"/>
</module>
Expand Down
2 changes: 1 addition & 1 deletion MultipleStringLiterals/Example3/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<property name="javaParseExceptionSeverity" value="ignore"/>

<module name="MultipleStringLiterals">
<property name="ignoreStringsRegexp" value="^(("")|(", "))$"/>
<property name="ignoreStringsRegexp" value='^(("")|(", "))$'/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</module>

<!-- suppress javadoc parsing errors, as we test Check not a parser -->
Expand Down
2 changes: 1 addition & 1 deletion MultipleStringLiterals/all-examples-in-one/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<module name="MultipleStringLiterals">
<property name="id" value="example3"/>
<property name="ignoreStringsRegexp" value="^(("")|(", "))$"/>
<property name="ignoreStringsRegexp" value='^(("")|(", "))$'/>
</module>

<module name="MultipleStringLiterals">
Expand Down
2 changes: 1 addition & 1 deletion Regexp/Example12/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<property name="javaParseExceptionSeverity" value="ignore"/>

<module name="Regexp">
<property name="format" value="\A/\*\n \* (\w*)\.java\n \*\n \* Copyright \(c\) \d\d\d\d ACME\n \* 123 Some St\.\n \* Somewhere\.\n \*\n \* This software is the confidential and proprietary information of ACME\.\n \* \("Confidential Information"\)\. You shall not disclose such\n \* Confidential Information and shall use it only in accordance with\n \* the terms of the license agreement you entered into with ACME\.\n \*\n \* \$Log: config_misc\.xml,v $ \* Revision 1\.7 2007/01/16 12:16:35 oburn \* Removing all reference to mailing lists \* \ \* Revision 1.6 2005/12/25 16:13:10 o_sukhodolsky \* Fix for rfe 1248106 \(TYPECAST is now accepted by NoWhitespaceAfter\) \* \ \* Fix for rfe 953266 \(thanks to Paul Guyot \(pguyot\) for submitting patch\) \* IllegalType can be configured to accept some abstract classes which \* matches to regexp of illegal type names \(property legalAbstractClassNames\) \* \* TrailingComment now can be configured to accept some trailing comments \* \(such as NOI18N\) \(property legalComment, rfe 1385344\). \* \* Revision 1.5 2005/11/06 11:54:12 oburn \* Incorporate excellent patch \[ 1344344 \] Consolidation of regexp checks. \* \\n(.*\n)*([\w|\s]*( class | interface )\1)"/>
<property name="format" value='\A/\*\n \* (\w*)\.java\n \*\n \* Copyright \(c\) \d\d\d\d ACME\n \* 123 Some St\.\n \* Somewhere\.\n \*\n \* This software is the confidential and proprietary information of ACME\.\n \* \("Confidential Information"\)\. You shall not disclose such\n \* Confidential Information and shall use it only in accordance with\n \* the terms of the license agreement you entered into with ACME\.\n \*\n \* \$Log: config_misc\.xml,v $ \* Revision 1\.7 2007/01/16 12:16:35 oburn \* Removing all reference to mailing lists \* \ \* Revision 1.6 2005/12/25 16:13:10 o_sukhodolsky \* Fix for rfe 1248106 \(TYPECAST is now accepted by NoWhitespaceAfter\) \* \ \* Fix for rfe 953266 \(thanks to Paul Guyot \(pguyot\) for submitting patch\) \* IllegalType can be configured to accept some abstract classes which \* matches to regexp of illegal type names \(property legalAbstractClassNames\) \* \* TrailingComment now can be configured to accept some trailing comments \* \(such as NOI18N\) \(property legalComment, rfe 1385344\). \* \* Revision 1.5 2005/11/06 11:54:12 oburn \* Incorporate excellent patch \[ 1344344 \] Consolidation of regexp checks. \* \\n(.*\n)*([\w|\s]*( class | interface )\1)'/>
<property name="message" value="Correct header not found"/>
</module>

Expand Down
2 changes: 1 addition & 1 deletion Regexp/Example13/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<module name="Regexp">
<property name="duplicateLimit" value="0"/>
<property name="format" value="(/\*\*\n)( \*.*\n)*( \* <P>\n \* <I> This software is the confidential and proprietary information of\n \* ACME \(<B>"Confidential Information"</B> \)\. 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\.</I>\n \* </P>\n \*\n \* © copyright \d\d\d\d ACME\n \*\n \* @author .*)(\n\s\*.*)*/\n[\w|\s]*( class | interface )"/>
<property name="format" value='(/\*\*\n)( \*.*\n)*( \* <P>\n \* <I> This software is the confidential and proprietary information of\n \* ACME \(<B>"Confidential Information"</B> \)\. 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\.</I>\n \* </P>\n \*\n \* © copyright \d\d\d\d ACME\n \*\n \* @author .*)(\n\s\*.*)*/\n[\w|\s]*( class | interface )'/>
<property name="message" value="Copyright in class/interface Javadoc"/>
</module>

Expand Down
4 changes: 2 additions & 2 deletions Regexp/all-examples-in-one/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@
</module>

<module name="Regexp">
<property name="format" value="\A/\*\n \* (\w*)\.java\n \*\n \* Copyright \(c\) \d\d\d\d ACME\n \* 123 Some St\.\n \* Somewhere\.\n \*\n \* This software is the confidential and proprietary information of ACME\.\n \* \("Confidential Information"\)\. You shall not disclose such\n \* Confidential Information and shall use it only in accordance with\n \* the terms of the license agreement you entered into with ACME\.\n \*\n \* \$Log: config_misc\.xml,v $ \* Revision 1\.7 2007/01/16 12:16:35 oburn \* Removing all reference to mailing lists \* \ \* Revision 1.6 2005/12/25 16:13:10 o_sukhodolsky \* Fix for rfe 1248106 \(TYPECAST is now accepted by NoWhitespaceAfter\) \* \ \* Fix for rfe 953266 \(thanks to Paul Guyot \(pguyot\) for submitting patch\) \* IllegalType can be configured to accept some abstract classes which \* matches to regexp of illegal type names \(property legalAbstractClassNames\) \* \* TrailingComment now can be configured to accept some trailing comments \* \(such as NOI18N\) \(property legalComment, rfe 1385344\). \* \* Revision 1.5 2005/11/06 11:54:12 oburn \* Incorporate excellent patch \[ 1344344 \] Consolidation of regexp checks. \* \\n(.*\n)*([\w|\s]*( class | interface )\1)"/>
<property name="format" value='\A/\*\n \* (\w*)\.java\n \*\n \* Copyright \(c\) \d\d\d\d ACME\n \* 123 Some St\.\n \* Somewhere\.\n \*\n \* This software is the confidential and proprietary information of ACME\.\n \* \("Confidential Information"\)\. You shall not disclose such\n \* Confidential Information and shall use it only in accordance with\n \* the terms of the license agreement you entered into with ACME\.\n \*\n \* \$Log: config_misc\.xml,v $ \* Revision 1\.7 2007/01/16 12:16:35 oburn \* Removing all reference to mailing lists \* \ \* Revision 1.6 2005/12/25 16:13:10 o_sukhodolsky \* Fix for rfe 1248106 \(TYPECAST is now accepted by NoWhitespaceAfter\) \* \ \* Fix for rfe 953266 \(thanks to Paul Guyot \(pguyot\) for submitting patch\) \* IllegalType can be configured to accept some abstract classes which \* matches to regexp of illegal type names \(property legalAbstractClassNames\) \* \* TrailingComment now can be configured to accept some trailing comments \* \(such as NOI18N\) \(property legalComment, rfe 1385344\). \* \* Revision 1.5 2005/11/06 11:54:12 oburn \* Incorporate excellent patch \[ 1344344 \] Consolidation of regexp checks. \* \\n(.*\n)*([\w|\s]*( class | interface )\1)'/>
<property name="id" value="example12"/>
<property name="message" value="Correct header not found"/>
</module>

<module name="Regexp">
<property name="duplicateLimit" value="0"/>
<property name="format" value="(/\*\*\n)( \*.*\n)*( \* <P>\n \* <I> This software is the confidential and proprietary information of\n \* ACME \(<B>"Confidential Information"</B> \)\. 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\.</I>\n \* </P>\n \*\n \* © copyright \d\d\d\d ACME\n \*\n \* @author .*)(\n\s\*.*)*/\n[\w|\s]*( class | interface )"/>
<property name="format" value='(/\*\*\n)( \*.*\n)*( \* <P>\n \* <I> This software is the confidential and proprietary information of\n \* ACME \(<B>"Confidential Information"</B> \)\. 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\.</I>\n \* </P>\n \*\n \* © copyright \d\d\d\d ACME\n \*\n \* @author .*)(\n\s\*.*)*/\n[\w|\s]*( class | interface )'/>
<property name="id" value="example13"/>
<property name="message" value="Copyright in class/interface Javadoc"/>
</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("<property name=\"").append(name)
.append("\" value=\"").append(value).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("<property name=\"")
.append(escapeXml(name))
.append("\" value=")
.append(quote)
.append(escapedValue)
.append(quote)
.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("\"", "&quot;")
.replace("'", "&apos;");
}
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("'", "&apos;");
}
else {
result = result.replace("\"", "&quot;");
}
}
return result;
}

/**
Expand Down
Loading