Skip to content

Commit

Permalink
Strip punctuation from attribution (#3287)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie authored Mar 6, 2025
1 parent 3e529c0 commit a188663
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions platform/darwin/src/MLNAttributionInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ @implementation MLNAttributionInfo
[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;
}
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/test/MLNAttributionInfoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ - (void)tearDown {
- (void)testParsing {
static NSString * const htmlStrings[] = {
@"<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">&copy; Mapbox</a> "
@"<a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">©️ OpenStreetMap</a> "
@"<a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">©️ OpenStreetMap</a>, "
@"CC&nbsp;BY-SA "
@"<a class=\"mapbox-improve-map\" href=\"https://apps.mapbox.com/feedback/\" target=\"_blank\">Improve this map</a>",
};
Expand Down

0 comments on commit a188663

Please sign in to comment.