fix: non-ascii character in URL can not open issue. resolve #304

This commit is contained in:
CMK 2022-04-11 12:27:26 +08:00
parent 33d68e8b6d
commit 67aa1d670b
3 changed files with 12 additions and 8 deletions

View File

@ -69,10 +69,10 @@ extension SearchHistorySection {
let trendHeaderRegister = UICollectionView.SupplementaryRegistration<SearchHistorySectionHeaderCollectionReusableView>(elementKind: UICollectionView.elementKindSectionHeader) { [weak dataSource] supplementaryView, elementKind, indexPath in let trendHeaderRegister = UICollectionView.SupplementaryRegistration<SearchHistorySectionHeaderCollectionReusableView>(elementKind: UICollectionView.elementKindSectionHeader) { [weak dataSource] supplementaryView, elementKind, indexPath in
supplementaryView.delegate = configuration.searchHistorySectionHeaderCollectionReusableViewDelegate supplementaryView.delegate = configuration.searchHistorySectionHeaderCollectionReusableViewDelegate
guard let dataSource = dataSource else { return } guard let _ = dataSource else { return }
let sections = dataSource.snapshot().sectionIdentifiers // let sections = dataSource.snapshot().sectionIdentifiers
guard indexPath.section < sections.count else { return } // guard indexPath.section < sections.count else { return }
let section = sections[indexPath.section] // let section = sections[indexPath.section]
} }
dataSource.supplementaryViewProvider = { (collectionView: UICollectionView, elementKind: String, indexPath: IndexPath) in dataSource.supplementaryViewProvider = { (collectionView: UICollectionView, elementKind: String, indexPath: IndexPath) in

View File

@ -38,11 +38,15 @@ extension DataSourceFacade {
meta: Meta meta: Meta
) async { ) async {
switch meta { switch meta {
// note:
// some server mark the normal url as "u-url" class. highlighted content is a URL
case .url(_, _, let url, _), case .url(_, _, let url, _),
.mention(_, let url, _) where url.lowercased().hasPrefix("http"): .mention(_, let url, _) where url.lowercased().hasPrefix("http"):
// note: // fix non-ascii character URL link can not open issue
// some server mark the normal url as "u-url" class. highlighted content is a URL guard let url = URL(string: url) ?? URL(string: url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? url) else {
guard let url = URL(string: url) else { return } assertionFailure()
return
}
if let domain = provider.context.authenticationService.activeMastodonAuthenticationBox.value?.domain, url.host == domain, if let domain = provider.context.authenticationService.activeMastodonAuthenticationBox.value?.domain, url.host == domain,
url.pathComponents.count >= 4, url.pathComponents.count >= 4,
url.pathComponents[0] == "/", url.pathComponents[0] == "/",

View File

@ -757,7 +757,7 @@ extension StatusView: UITextViewDelegate {
// MARK: - MetaTextViewDelegate // MARK: - MetaTextViewDelegate
extension StatusView: MetaTextViewDelegate { extension StatusView: MetaTextViewDelegate {
public func metaTextView(_ metaTextView: MetaTextView, didSelectMeta meta: Meta) { public func metaTextView(_ metaTextView: MetaTextView, didSelectMeta meta: Meta) {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)") logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): meta: \(String(describing: meta))")
switch metaTextView { switch metaTextView {
case contentMetaText.textView: case contentMetaText.textView:
delegate?.statusView(self, metaText: contentMetaText, didSelectMeta: meta) delegate?.statusView(self, metaText: contentMetaText, didSelectMeta: meta)