Skip to content

test: cover malformed percent-encoded sequences - #459

Closed
Palendromas1 wants to merge 3 commits into
apache:masterfrom
Palendromas1:trabalho-prs
Closed

Palendromas1 wants to merge 3 commits into
apache:masterfrom
Palendromas1:trabalho-prs

Conversation

@Palendromas1

Copy link
Copy Markdown

Summary

Adds test coverage for malformed percent-encoded sequences in PercentCodec.

Changes

  • Tests incomplete escape sequences (% and %2).
  • Tests invalid hexadecimal sequences (%GG and %2G).
  • Verifies that malformed inputs throw DecoderException.

Validation

  • mvn -Dtest=PercentCodecTest test
  • 16 tests executed, 0 failures, 0 errors.

@garydgregory
garydgregory marked this pull request as draft November 18, 2026 22:17
@garydgregory

Copy link
Copy Markdown
Member

@Palendromas1

The coverage is useful, but this PR needs a few improvements before merging. See commit afaeeac.

In this PR:

  • %2 overlaps testDecodeInvalidEncodedResultDecoding, while leaving that existing test’s weakness intact: its try/catch passes if decoding throws nothing.
  • %GG does not independently verify first-digit validation. If that validation breaks, the second G still produces the expected exception. I confirmed this with a temporary mutation.
  • The repeated malformed-input assertions are better expressed as parameterized tests, which also report each failing input separately.

My commit afaeeac replaces the existing truncation test with parameterized cases, preserving its valid-prefix scenario and exception-cause assertion. A separate parameterized test uses %G2 and %2G to verify each hex digit independently.

It also retains the Javadoc clarification and the distinct RFC1522 empty-content test, with a comment explaining that accepting empty content preserves existing permissive behavior.

This provides stronger regression protection without accumulating overlapping test methods. Temporary mutation checks confirmed that the revised tests detect broken validation of either digit, swallowed truncation errors, and lost exception causes.

Closing; you are credited in changes.xml.

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.

2 participants