antisamy icon indicating copy to clipboard operation
antisamy copied to clipboard

MagicSaxFilter.java will add an extra rel="..." attribute if the existing one is the first attribute

Open LanceNeumannBlackboard opened this issue 6 months ago • 4 comments

This block of code in MagicSaxFilter:

if ((relIndex = validattributes.getIndex("rel")) > 0) {
              validattributes.setValue(relIndex, relValue);
            } else {
              validattributes.addAttribute(makeSimpleQname("rel"), "CDATA", relValue);
            }

will incorrectly add a second rel attribute if the first attribute is rel. Fix: Change that condition to >= 0

Example <a rel="nofollow" othervalidattributes> will end up being rewritten as <a rel="nofollow" othervalidattributes rel="nofollow>

LanceNeumannBlackboard avatar Jun 09 '25 21:06 LanceNeumannBlackboard

@spassarop - Can you look into this?

davewichers avatar Jun 09 '25 21:06 davewichers

@LanceNeumannBlackboard you are right. Current tests do not have the rel attribute first so it never came up. I created PR #588 with the fix and specific tests that basically count the number of rel occurrences.

spassarop avatar Jun 19 '25 20:06 spassarop

@LanceNeumannBlackboard - I've merged @spassarop's change into the main branch. Can you build/test this locally to confirm this fixes your issue?

davewichers avatar Jun 23 '25 15:06 davewichers

Sorry - missed your update last month. I tried your change with 1.7.9-SNAPSHOT built locally and it works as expected.

LanceNeumannBlackboard avatar Jul 18 '25 15:07 LanceNeumannBlackboard