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

bugfix for issue #11 (skip xml entities in filter method) #12

Merged
merged 7 commits into from
Oct 22, 2023

Conversation

jo-kl
Copy link
Collaborator

@jo-kl jo-kl commented Jul 7, 2023

No description provided.

@jo-kl jo-kl requested a review from ste-gr July 7, 2023 05:04
@ste-gr ste-gr linked an issue Jul 7, 2023 that may be closed by this pull request
assertEquals("123Ī456", ResponseUtils.filter("123Ī456"));
assertEquals("123&#x12ah;456", ResponseUtils.filter("123&#x12ah;456"));
assertEquals("123&lt;&gt;&quot;&#39;456", ResponseUtils.filter("123<>\"'456"));
}
Copy link
Member

Choose a reason for hiding this comment

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

I think the test-case "123&Uuml;456" will not work. Could you also add this case please.

assertEquals("123&amp;#12a;456", ResponseUtils.filter("123&#12a;456"));
assertEquals("123&#x12a;456", ResponseUtils.filter("123&#x12a;456"));
assertEquals("123&amp;#x12ah;456", ResponseUtils.filter("123&#x12ah;456"));
assertEquals("123&lt;&gt;&quot;&#39;456", ResponseUtils.filter("123<>\"'456"));
Copy link
Member

Choose a reason for hiding this comment

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

The test-case "123&456;789" should return "123&amp;456;789" because the "NameStartChar" is not allowed to begin with an number. See https://www.w3.org/TR/xml/#NT-Name

filtered = "&amp;";

if ( isStartOfXmlEntity(value,i) ) {
filtered = "&"; // leave unchanged
Copy link
Member

Choose a reason for hiding this comment

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

When unchanged, it's not needed to set filtered.

@@ -35,6 +37,9 @@
* $
*/
public class ResponseUtils {

protected static Pattern XML_ENTITY_PATTERN = Pattern.compile("&(?:[a-z\\d]+|#\\d+|#x[a-f\\d]+);");
Copy link
Member

Choose a reason for hiding this comment

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

See also the suggested test-cases.

Suggested change
protected static Pattern XML_ENTITY_PATTERN = Pattern.compile("&(?:[a-z\\d]+|#\\d+|#x[a-f\\d]+);");
protected static Pattern XML_ENTITY_PATTERN = Pattern.compile("&(?:[a-zA-Z][a-zA-Z\\d]*|#\\d+|#x[a-fA-F\\d]+);");

@@ -82,8 +87,11 @@ public static String filter(String value) {
break;

case '&':
filtered = "&amp;";

if ( isStartOfXmlEntity(value,i) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Please delete blanks after ( and before ), thanks.

Suggested change
if ( isStartOfXmlEntity(value,i) ) {
if (isStartOfXmlEntity(value,i)) {

*/
private static boolean isStartOfXmlEntity(String str, int startpos) {
Matcher matcher = XML_ENTITY_PATTERN.matcher(str.substring(startpos));
if ( matcher.find() && matcher.start() == 0 ) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ( matcher.find() && matcher.start() == 0 ) {
return matcher.find() && matcher.start() == 0;

@jo-kl jo-kl requested a review from ste-gr July 24, 2023 06:00
@TimCincotta
Copy link

TimCincotta commented Sep 18, 2023 via email

@ste-gr
Copy link
Member

ste-gr commented Sep 24, 2023

Hi Tim,

It would be nice to get some interesting new ideas and support to make Struts1 ready for JEE9+. I have opened the discussion [#14].

Currently it has the following status:

  • I have started to change the namespaces from javax to jakarta.
  • Unfortunately, the following dependencies are not yet JEE9+ compatible:

Nice to have, but not necessary:

Regards
Stefan

@ste-gr ste-gr merged commit ccd2d45 into main Oct 22, 2023
@ste-gr ste-gr deleted the bugfix/issue#11 branch October 22, 2023 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XML Entities not handled correctly
3 participants