Skip to content

Commit

Permalink
Merge pull request #23 from mateuszjablonski-slabs/key_quote_escaping
Browse files Browse the repository at this point in the history
Key quote escaping
  • Loading branch information
olejnjak authored Nov 3, 2020
2 parents 6c9cfce + cdbb7ca commit 6d80324
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@

## master

## 1.1.3

### Fixed
- Fix creating invalid keys, if contain quote marks ([#22](https://github.com/AckeeCZ/ACKLocalization/pull/22), kudos to @mateuszjablonski)

## 1.1.2

### Fixed
- Fix creating empty files when spreadsheet doesn't contain any plurals or only plurals ([#20](https://github.com/AckeeCZ/ACKLocalization/pull/17), kudos to @olejnjak)
- Fix creating empty files when spreadsheet doesn't contain any plurals or only plurals ([#20](https://github.com/AckeeCZ/ACKLocalization/pull/20), kudos to @olejnjak)

## 1.1.1

Expand Down
8 changes: 7 additions & 1 deletion Sources/ACKLocalizationCore/Model/LocRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct LocRow {
public let value: String

/// Representation that can be used as row in strings file
public var localizableRow: String { return "\"" + key + "\" = \"" + normalizedValue + "\";" }
public var localizableRow: String { return "\"" + normalizedKey + "\" = \"" + normalizedValue + "\";" }

// MARK: - Initializers

Expand All @@ -26,6 +26,12 @@ public struct LocRow {
}

// MARK: - Private helpers

/// Key with replaced quotes
private var normalizedKey: String {
return key
.replacingOccurrences(of: "\"", with: "\\\"")
}

/// Value with replaced placeholder arguments
private var normalizedValue: String {
Expand Down
7 changes: 6 additions & 1 deletion Tests/ACKLocalizationCoreTests/LocRowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ final class LocRowTests: XCTestCase {
XCTAssertEqual("\"percent_key\" = \"%d %% percent\";", locRow.localizableRow)
}

func testQuotesAreEscaped() {
func testKeyQuotesAreEscaped() {
let locRow = LocRow(key: "abc\"abc", value: "quotes_value")
XCTAssertEqual("\"abc\\\"abc\" = \"quotes_value\";", locRow.localizableRow)
}

func testValueQuotesAreEscaped() {
let locRow = LocRow(key: "quotes_key", value: "abc\"abc")
XCTAssertEqual("\"quotes_key\" = \"abc\\\"abc\";", locRow.localizableRow)
}
Expand Down

0 comments on commit 6d80324

Please sign in to comment.