From fcbc491180fabfbb6453da17baaaa042c3d17bdf Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 6 Nov 2026 10:33:49 -0800 Subject: [PATCH] Rename forNameCaseInsensitive to forCaseInsensitiveName. --- .../Sources/RSParser/Feeds/XML/MediaRSS.swift | 20 +++++++++---------- .../RSParser/Feeds/XML/RSSParser.swift | 2 +- .../Sources/RSParser/XML/XMLAttributes.swift | 2 +- .../XML/XMLAttributesTests.swift | 12 +++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Modules/RSParser/Sources/RSParser/Feeds/XML/MediaRSS.swift b/Modules/RSParser/Sources/RSParser/Feeds/XML/MediaRSS.swift index c71c9983d..05e32bcf2 100644 --- a/Modules/RSParser/Sources/RSParser/Feeds/XML/MediaRSS.swift +++ b/Modules/RSParser/Sources/RSParser/Feeds/XML/MediaRSS.swift @@ -13,13 +13,13 @@ enum MediaRSS { /// Attachment from a `media:content` element’s attributes. `url` is the resolved `url` attribute. static func attachment(url: String, attributes: XMLAttributes) -> ParsedAttachment? { - let mimeType = attributes.value(forNameCaseInsensitive: "type") + let mimeType = attributes.value(forCaseInsensitiveName: "type") // The spec says fileSize. Some feeds (atp.fm) use length, as in RSS enclosures. - let sizeInBytes = positiveInt(attributes.value(forNameCaseInsensitive: "fileSize") ?? attributes.value(forNameCaseInsensitive: "length")) - let durationInSeconds = ParsedAttachment.durationInSeconds(attributes.value(forNameCaseInsensitive: "duration")) - let width = positiveInt(attributes.value(forNameCaseInsensitive: "width")) - let height = positiveInt(attributes.value(forNameCaseInsensitive: "height")) - let mediumValue = attributes.value(forNameCaseInsensitive: "medium") + let sizeInBytes = positiveInt(attributes.value(forCaseInsensitiveName: "fileSize") ?? attributes.value(forCaseInsensitiveName: "length")) + let durationInSeconds = ParsedAttachment.durationInSeconds(attributes.value(forCaseInsensitiveName: "duration")) + let width = positiveInt(attributes.value(forCaseInsensitiveName: "width")) + let height = positiveInt(attributes.value(forCaseInsensitiveName: "height")) + let mediumValue = attributes.value(forCaseInsensitiveName: "medium") let medium = ParsedAttachment.Medium(mediaRSSValue: mediumValue) return ParsedAttachment(url: url, mimeType: mimeType, title: nil, sizeInBytes: sizeInBytes, durationInSeconds: durationInSeconds, width: width, height: height, medium: medium) @@ -38,7 +38,7 @@ enum MediaRSS { } static func isDefault(_ attributes: XMLAttributes) -> Bool { - attributes.value(forNameCaseInsensitive: "isDefault")?.lowercased() == "true" + attributes.value(forCaseInsensitiveName: "isDefault")?.lowercased() == "true" } private static func positiveInt(_ s: String?) -> Int? { @@ -78,7 +78,7 @@ struct MediaElementTracker { } if localName.equals("content") { - if let urlString = attributes.value(forNameCaseInsensitive: "url"), let url = resolveURL(urlString), let attachment = MediaRSS.attachment(url: url, attributes: attributes) { + if let urlString = attributes.value(forCaseInsensitiveName: "url"), let url = resolveURL(urlString), let attachment = MediaRSS.attachment(url: url, attributes: attributes) { if group != nil { group?.add(attachment, isDefault: MediaRSS.isDefault(attributes)) } else { @@ -100,14 +100,14 @@ struct MediaElementTracker { if localName.equals("description") { if item.mediaDescription == nil { - item.mediaDescriptionIsHTML = attributes.value(forNameCaseInsensitive: "type")?.lowercased() == "html" + item.mediaDescriptionIsHTML = attributes.value(forCaseInsensitiveName: "type")?.lowercased() == "html" parser.beginStoringCharacters() } containerDepth += 1 return false } - if localName.equals("thumbnail"), item.thumbnailURL == nil, let urlString = attributes.value(forNameCaseInsensitive: "url"), !urlString.isEmpty { + if localName.equals("thumbnail"), item.thumbnailURL == nil, let urlString = attributes.value(forCaseInsensitiveName: "url"), !urlString.isEmpty { item.thumbnailURL = resolveURL(urlString) } return true diff --git a/Modules/RSParser/Sources/RSParser/Feeds/XML/RSSParser.swift b/Modules/RSParser/Sources/RSParser/Feeds/XML/RSSParser.swift index 12ce2daa4..d983090d7 100644 --- a/Modules/RSParser/Sources/RSParser/Feeds/XML/RSSParser.swift +++ b/Modules/RSParser/Sources/RSParser/Feeds/XML/RSSParser.swift @@ -101,7 +101,7 @@ private final class RSSDelegate: XMLSAXParserDelegate { return } if parsingArticle && namespace.isITunes && localName.equals("image") { - if let currentItem, currentItem.itunesImageURL == nil, let href = attributes.value(forNameCaseInsensitive: "href"), !href.isEmpty { + if let currentItem, currentItem.itunesImageURL == nil, let href = attributes.value(forCaseInsensitiveName: "href"), !href.isEmpty { currentItem.itunesImageURL = resolveURL(href) } namespaceElementDepth = 1 diff --git a/Modules/RSParser/Sources/RSParser/XML/XMLAttributes.swift b/Modules/RSParser/Sources/RSParser/XML/XMLAttributes.swift index a81879dba..7fc065fd0 100644 --- a/Modules/RSParser/Sources/RSParser/XML/XMLAttributes.swift +++ b/Modules/RSParser/Sources/RSParser/XML/XMLAttributes.swift @@ -61,7 +61,7 @@ public struct XMLAttributes: Sendable { } /// For feeds with messed up casing (`isPermaLink` vs `ispermalink`). - public func value(forNameCaseInsensitive name: String) -> String? { + public func value(forCaseInsensitiveName name: String) -> String? { value(forName: name, caseInsensitive: true) } diff --git a/Modules/RSParser/Tests/RSParserTests/XML/XMLAttributesTests.swift b/Modules/RSParser/Tests/RSParserTests/XML/XMLAttributesTests.swift index 165c3f102..57626435c 100644 --- a/Modules/RSParser/Tests/RSParserTests/XML/XMLAttributesTests.swift +++ b/Modules/RSParser/Tests/RSParserTests/XML/XMLAttributesTests.swift @@ -116,22 +116,22 @@ import Testing @Test func caseInsensitiveMatchesMixedCaseLocalName() { // RSS's `isPermaLink` vs authors typing `ispermalink`. let a = make(makeAttribute(localName: "isPermaLink", value: "false")) - #expect(a.value(forNameCaseInsensitive: "ispermalink") == "false") - #expect(a.value(forNameCaseInsensitive: "ISPERMALINK") == "false") - #expect(a.value(forNameCaseInsensitive: "IsPermaLink") == "false") + #expect(a.value(forCaseInsensitiveName: "ispermalink") == "false") + #expect(a.value(forCaseInsensitiveName: "ISPERMALINK") == "false") + #expect(a.value(forCaseInsensitiveName: "IsPermaLink") == "false") } @Test func caseInsensitiveMatchesPrefixAndLocal() { let a = make(makeAttribute(prefix: "XML", localName: "Lang", value: "en", uri: "http://www.w3.org/XML/1998/namespace")) - #expect(a.value(forNameCaseInsensitive: "xml:lang") == "en") + #expect(a.value(forCaseInsensitiveName: "xml:lang") == "en") } @Test func caseInsensitiveDoesNotAffectNonLetters() { // Hyphens/digits/punctuation compare byte-for-byte even under case-insensitive. let a = make(makeAttribute(localName: "data-id", value: "42")) - #expect(a.value(forNameCaseInsensitive: "data-id") == "42") - #expect(a.value(forNameCaseInsensitive: "data_id") == nil) + #expect(a.value(forCaseInsensitiveName: "data-id") == "42") + #expect(a.value(forCaseInsensitiveName: "data_id") == nil) } // MARK: - dictionary()