Skip to content

Commit 5c184ee

Browse files
committed
Fix XML parser to deal with entities
1 parent 59ba506 commit 5c184ee

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

lib/pmdtester/parsers/pmd_report_document.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def remove_work_dir!(str)
4747
end
4848

4949
def characters(string)
50-
@current_violation&.text = string
50+
@current_violation&.text += string
5151
end
5252

5353
def end_element(name)
@@ -56,6 +56,7 @@ def end_element(name)
5656
@violations.add_violations_by_filename(@current_filename, @current_violations)
5757
@current_filename = nil
5858
when 'violation'
59+
@current_violation&.text.strip!
5960
@current_violations.push(@current_violation) if match_filter_set?(@current_violation)
6061
@current_violation = nil
6162
when 'error'

test/resources/pmd_report_document/test_document.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
version="6.3.0-SNAPSHOT" timestamp="2018-04-16T22:41:45.065">
66
<file name="SHOULD_BE_REPLACED/target/repositories/spring-framework/gradle/jdiff/Null.java">
77
<violation beginline="7" endline="8" begincolumn="12" endcolumn="5" rule="UncommentedEmptyConstructor" ruleset="Documentation" class="Null" method="Null" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_documentation.html#uncommentedemptyconstructor" priority="3">
8-
Document empty constructor
8+
Document &apos;empty&apos; constructor
99
</violation>
1010
</file>
1111
<file name="SHOULD_BE_REPLACED/target/repositories/spring-framework/spring-aop/src/main/java/org/springframework/aop/ClassFilter.java">

test/test_pmd_report_document.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def test_document
99
parser = Nokogiri::XML::SAX::Parser.new(doc)
1010
parser.parse(File.open('test/resources/pmd_report_document/test_document.xml'))
1111
assert_equal(8, doc.violations.violations_size)
12+
assert_equal('Document \'empty\' constructor', doc.violations.violations['/target/repositories/spring-framework/gradle/jdiff/Null.java'][0].text)
1213
assert_equal(2, doc.errors.errors_size)
1314
pmd_errors = doc.errors.errors.values
1415
assert_not_nil(pmd_errors[0])

0 commit comments

Comments
 (0)