Strip punctuation from attribution (#3287)

This commit is contained in:
Ian Wagner
2025-03-06 23:42:48 +09:00
committed by GitHub
parent 3e529c0995
commit a188663a87
2 changed files with 7 additions and 3 deletions

View File

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

View File

@@ -20,7 +20,7 @@
- (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>",
};