Repository navigation
Give the eBay and Slashdot examples a run(Reader, Appendable) method - #418
Merged
Merged
Conversation
The two stdin-to-stdout examples did all their work inside main, so the only test of them swapped System.in, System.out and System.err for capture buffers, invoked main reflectively, and could only feed them empty input. The Slashdot policy had no direct test at all. Each example now has a public run(Reader, Appendable) that does the sanitizing, as UrlTextExample.run already did; main keeps its command line handling and delegates. ExamplesTest calls the examples directly and asserts real output for both policies. AllExamples, which existed only to drive the reflective test, is gone. The javadoc exclusion pattern `*.example` never matched the `org.owasp.html.examples` package, so the examples have shipped in the published javadoc since the pattern was added; it is now `*.examples`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BZfawfTUAFHN7cocUjcpQK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #415. The review of that PR left two suggestions open; this resolves the one that turned out to have real value and drops the other.
Why
The two stdin-to-stdout examples did all their work inside
main, so the only test of them swappedSystem.in,System.outandSystem.errfor capture buffers, invokedmainreflectively, and could only feed them empty input. That was the last test in the suite that mutates process-global state. It also hid a coverage gap:SlashdotPolicyExample.POLICY_DEFINITIONhad no direct test anywhere, and no non-empty input ever passed through either example.What changes
EbayPolicyExampleandSlashdotPolicyExamplegainpublic static void run(Reader in, Appendable out), the same shapeUrlTextExample.runalready had.mainkeeps its command-line handling (usage message,[Reading from STDIN]notice) and delegates. Purely additive; the package is not OSGi-exported.ExamplesTestcalls the examples directly with aStringReaderandStringBuilder: an empty-input case for all three, plus real-content assertions for the Slashdot and eBay policies covering allowed markup, attribute canonicalization,rel="nofollow", and droppedscript,iframe, event handlers andjavascript:links. No reflection, no stream swapping, no parameterized test.AllExamplesexisted only to drive the old test and is removed.*.examplenever matched theorg.owasp.html.examplespackage, so the examples have shipped in the published javadoc since the pattern was added. It is now*.examples. Verified by runningjavadoc:javadocwith each pattern: the old one leavesorg/owasp/html/examplesin the output, the new one removes it, with the 38 core pages unchanged.Not done, deliberately: the Surefire display-name reporter suggested in the same review. Nothing machine-reads the reports, and with the parameterized test gone there is nothing left to rename.
Verification
./mvnw clean verifyon JDK 11: 381 tests, 0 failures, 0 skipped (unchanged total;ExamplesTeststill contributes 6). A grep ofsrc/testforSystem.setIn,setOut,setErr,getDeclaredMethod,ParameterizedTestorAllExamplesreturns nothing.🤖 Generated with Claude Code
https://claude.ai/code/session_01BZfawfTUAFHN7cocUjcpQK