From a188663a872249a09dc630b762da19c2a9f24471 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Thu, 6 Mar 2025 23:42:48 +0900 Subject: [PATCH] Strip punctuation from attribution (#3287) --- platform/darwin/src/MLNAttributionInfo.mm | 8 ++++++-- platform/darwin/test/MLNAttributionInfoTests.m | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/platform/darwin/src/MLNAttributionInfo.mm b/platform/darwin/src/MLNAttributionInfo.mm index 42b4dc935..0de8e407a 100644 --- a/platform/darwin/src/MLNAttributionInfo.mm +++ b/platform/darwin/src/MLNAttributionInfo.mm @@ -104,9 +104,13 @@ [attributedString removeAttribute:NSStrokeWidthAttributeName range:range]; } - // Omit whitespace-only strings. + // Clean up strings by stripping punctuation and whitespace (often present for the web). + NSMutableCharacterSet *charset = [NSMutableCharacterSet whitespaceAndNewlineCharacterSet]; + [charset formUnionWithCharacterSet:[NSCharacterSet punctuationCharacterSet]]; NSAttributedString *title = [[attributedString attributedSubstringFromRange:range] - mgl_attributedStringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + mgl_attributedStringByTrimmingCharactersInSet:charset]; + + // Omit strings that are empty after cleaning. if (!title.length) { return; } diff --git a/platform/darwin/test/MLNAttributionInfoTests.m b/platform/darwin/test/MLNAttributionInfoTests.m index 340dce49b..612716f25 100644 --- a/platform/darwin/test/MLNAttributionInfoTests.m +++ b/platform/darwin/test/MLNAttributionInfoTests.m @@ -20,7 +20,7 @@ - (void)testParsing { static NSString * const htmlStrings[] = { @"© Mapbox " - @"©️ OpenStreetMap " + @"©️ OpenStreetMap, " @"CC BY-SA " @"Improve this map", };