Skip to content
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

Closed
wants to merge 12 commits into from
Closed

Fix XML Reporters not Escaping Characters #969

wants to merge 12 commits into from

Conversation

fabb
Copy link
Contributor

@fabb fabb commented Dec 12, 2016

Fixes #968.

@codecov-io
Copy link

codecov-io commented Dec 12, 2016

Current coverage is 81.16% (diff: 95.16%)

Merging #969 into master will increase coverage by 0.20%

@@             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          

Powered by Codecov. Last update 288a3ec...402d55c

@@ -0,0 +1,25 @@
//
// CheckstyleReporter.swift
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong filename

Copy link
Contributor Author

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
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, moved it

@marcelofabri
Copy link
Collaborator

Thanks for this! Could you add a changelog entry? Check https://github.com/realm/SwiftLint/blob/master/CONTRIBUTING.md#tracking-changes

Copy link
Collaborator

@jpsim jpsim left a 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>"
Copy link
Collaborator

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()

Copy link
Contributor Author

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() ?? ""
Copy link
Collaborator

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()

Copy link
Contributor Author

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>"
Copy link
Collaborator

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()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@fabb
Copy link
Contributor Author

fabb commented Dec 13, 2016

Sorry for not reading CONRIBUTING.md 🤦

@@ -88,7 +127,11 @@ class ReporterTests: XCTestCase {
CSVReporter.generateReport(generateViolations()),
Copy link
Contributor Author

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
Copy link
Collaborator

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

Copy link
Contributor Author

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 {
Copy link
Collaborator

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()

Copy link
Contributor Author

@fabb fabb left a 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,
Copy link
Contributor Author

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
Copy link
Contributor Author

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, done: #976

Copy link
Collaborator

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
Copy link
Contributor Author

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 ;-)

@jpsim
Copy link
Collaborator

jpsim commented Dec 13, 2016

Thanks for pushing this forward @fabb! I've made some small changes and addressed the merge conflicts so I'll be merging this as part of #979.

@jpsim jpsim closed this Dec 13, 2016
@fabb
Copy link
Contributor Author

fabb commented Dec 14, 2016

Awesome, thanks a lot!

@fabb fabb deleted the fix_xml branch December 14, 2016 07:06
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.

4 participants