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 localization crash on iOS 11 and 12 #1278

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone.

* Add support for runtime source properties. ([#1267](https://github.com/mapbox/mapbox-maps-ios/pull/1267))
* Start location services lazily. ([#1262](https://github.com/mapbox/mapbox-maps-ios/pull/1262))
* Fix localization crash on iOS 11 and 12. ([#1278](https://github.com/mapbox/mapbox-maps-ios/pull/1278))

## 10.5.0-beta.1 - April 7, 2022

Expand Down
4 changes: 2 additions & 2 deletions Sources/MapboxMaps/Style/Style+Localization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ extension Style {
let expressionAbbr = try NSRegularExpression(pattern: "\\[\"get\",\\s*\"abbr\"\\]",
options: .caseInsensitive)

if var stringExpression = String(data: try JSONEncoder().encode(symbolLayer.textField), encoding: .utf8),
stringExpression != "null" {
if case .expression(let textField) = symbolLayer.textField,
var stringExpression = String(data: try JSONEncoder().encode(textField), encoding: .utf8) {
stringExpression.updateOnceExpression(replacement: replacement, regex: expressionCoalesce)
stringExpression.updateExpression(replacement: replacement, regex: expressionAbbr)

Expand Down
17 changes: 17 additions & 0 deletions Tests/MapboxMapsTests/Style/Style+LocalizationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,21 @@ final class StyleLocalizationTests: MapViewIntegrationTestCase {
}
))
}

func testSkipsSymbolLayersWhereTextFieldIsNil() throws {
var source = GeoJSONSource()
source.data = .feature(Feature(geometry: Point(CLLocationCoordinate2D(latitude: 0, longitude: 0))))
try style.addSource(source, id: "a")

var symbolLayer = SymbolLayer(id: "a")
symbolLayer.source = "a"

try style.addLayer(symbolLayer)

try style.localizeLabels(into: Locale(identifier: "de"))

let updatedLayer = try style.layer(withId: "a", type: SymbolLayer.self)

XCTAssertNil(updatedLayer.textField)
}
}