-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix XML Reporters not Escaping Characters #969
Conversation
…tains characters '<' and '>' which are not allowed in xml or html
Current coverage is 81.16% (diff: 95.16%)@@ master #969 diff @@
==========================================
Files 123 124 +1
Lines 5774 5825 +51
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 4675 4728 +53
+ Misses 1099 1097 -2
Partials 0 0
|
@@ -0,0 +1,25 @@ | |||
// | |||
// CheckstyleReporter.swift |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong filename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch :-)
@@ -0,0 +1,25 @@ | |||
// | |||
// CheckstyleReporter.swift |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, there's an "Extensions" group/folder, this file probably belong there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, moved it
Thanks for this! Could you add a changelog entry? Check https://github.com/realm/SwiftLint/blob/master/CONTRIBUTING.md#tracking-changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a changelog entry.
@@ -25,11 +25,11 @@ public struct CheckstyleReporter: Reporter { | |||
} | |||
|
|||
private static func generateForSingleViolation(_ violation: StyleViolation) -> String { | |||
let file: String = violation.location.file ?? "<nopath>" | |||
let file: String = violation.location.file?.escapedForXml() ?? "<nopath>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"<nopath>"
needs to be escaped: (violation.location.file ?? "<nopath>").escapedForXml()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, good catch! i added an example to the unit tests
@@ -120,7 +120,7 @@ public struct HTMLReporter: Reporter { | |||
private static func generateSingleRow(for violation: StyleViolation, at index: Int) -> String { | |||
let severity: String = violation.severity.rawValue.capitalized | |||
let location = violation.location | |||
let file: String = location.file ?? "" | |||
let file: String = location.file?.escapedForXml() ?? "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably use "<nopath>"
here too for consistency with CheckstyleReporter.swift
: (location.file ?? "<nopath>").escapedForXml()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -19,11 +19,12 @@ public struct JUnitReporter: Reporter { | |||
public static func generateReport(_ violations: [StyleViolation]) -> String { | |||
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<testsuites><testsuite>" + | |||
violations.map({ violation in | |||
let fileName = violation.location.file ?? "<nopath>" | |||
let fileName = violation.location.file?.escapedForXml() ?? "<nopath>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"<nopath>"
needs to be escaped: (violation.location.file ?? "<nopath>").escapedForXml()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry for not reading CONRIBUTING.md 🤦 |
@@ -88,7 +127,11 @@ class ReporterTests: XCTestCase { | |||
CSVReporter.generateReport(generateViolations()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there newlines missing in the CSVReporter output? right now all is just a single line. (out of scope of this PR though)
@@ -61,6 +61,10 @@ | |||
[Marcelo Fabri](https://github.com/marcelofabri) | |||
[#934](https://github.com/realm/SwiftLint/issues/934) | |||
|
|||
* Fix XML reporters not escaping characters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still missing trailing period, followed by two spaces: https://github.com/realm/SwiftLint/blob/master/CONTRIBUTING.md#tracking-changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should lint that file in the unit tests ;-)
// | ||
|
||
extension String { | ||
func escapedForXml() -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice if XML
was capitalized: escapedForXML()
…ept html reporter output, as that includes parametrized stuff
# Conflicts: # CHANGELOG.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes as suggested
location: location, | ||
reason: "Shorthand syntactic sugar should be used" + | ||
", i.e. [Int] instead of Array<Int>."), | ||
StyleViolation(ruleDescription: ColonRule.description, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since i added the extra violations, xcode becomes unresponsive for 10-20 seconds every time i open this file. i guess Xcode/SourceKit cannot cope with that many string appendings. I moved the expectation strings to other files - hope that's allright
} | ||
|
||
// swiftlint:disable function_body_length | ||
// swiftlint:disable line_length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tried these 2 variants, but it didn't work:
// swiftlint:disable function_body_length line_length
// swiftlint:disable:next function_body_length
// swiftlint:disable:next line_length
bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, could you please file a new ticket for this? I don't think my quick implementation from last week is 100% correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, done: #976
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #978, thanks!
@@ -61,6 +61,10 @@ | |||
[Marcelo Fabri](https://github.com/marcelofabri) | |||
[#934](https://github.com/realm/SwiftLint/issues/934) | |||
|
|||
* Fix XML reporters not escaping characters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should lint that file in the unit tests ;-)
Awesome, thanks a lot! |
Fixes #968.