From e5d5402098752defd3f7d59fd47a5ba0250e6368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=80=E1=85=AA=E1=86=BC?= =?UTF-8?q?=E1=84=92=E1=85=A7=E1=86=AB?= Date: Thu, 31 Mar 2022 05:23:34 +0900 Subject: [PATCH 1/2] Fix the problem that other string after url are recognized as url --- ActiveLabel.xcodeproj/project.pbxproj | 4 ++++ ActiveLabel/RegexParser.swift | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ActiveLabel.xcodeproj/project.pbxproj b/ActiveLabel.xcodeproj/project.pbxproj index 311e4a1c..2ced28ca 100644 --- a/ActiveLabel.xcodeproj/project.pbxproj +++ b/ActiveLabel.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ C1D15C791D7C9B610041D119 /* StringTrimExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D15C781D7C9B610041D119 /* StringTrimExtension.swift */; }; C1D15C7B1D7C9B7E0041D119 /* ActiveBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D15C7A1D7C9B7E0041D119 /* ActiveBuilder.swift */; }; C1E867D61C3D7AEA00FD687A /* RegexParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E867D51C3D7AEA00FD687A /* RegexParser.swift */; }; + CE3BE93D27F4F34D006A3145 /* RegexParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3BE93C27F4F34D006A3145 /* RegexParserTest.swift */; }; E267FA251DB3A34900EEAC4C /* ActiveLabel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8F0249A21B9989B1005D8035 /* ActiveLabel.framework */; }; E267FA261DB3A34900EEAC4C /* ActiveLabel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8F0249A21B9989B1005D8035 /* ActiveLabel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ @@ -74,6 +75,7 @@ C1D15C781D7C9B610041D119 /* StringTrimExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringTrimExtension.swift; sourceTree = ""; }; C1D15C7A1D7C9B7E0041D119 /* ActiveBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActiveBuilder.swift; sourceTree = ""; }; C1E867D51C3D7AEA00FD687A /* RegexParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegexParser.swift; sourceTree = ""; }; + CE3BE93C27F4F34D006A3145 /* RegexParserTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegexParserTest.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -141,6 +143,7 @@ isa = PBXGroup; children = ( 8F0249B11B9989B1005D8035 /* ActiveTypeTests.swift */, + CE3BE93C27F4F34D006A3145 /* RegexParserTest.swift */, 8F0249B31B9989B1005D8035 /* Info.plist */, ); path = ActiveLabelTests; @@ -317,6 +320,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CE3BE93D27F4F34D006A3145 /* RegexParserTest.swift in Sources */, 8F0249B21B9989B1005D8035 /* ActiveTypeTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/ActiveLabel/RegexParser.swift b/ActiveLabel/RegexParser.swift index fe9bd7ab..cbf41402 100644 --- a/ActiveLabel/RegexParser.swift +++ b/ActiveLabel/RegexParser.swift @@ -13,9 +13,7 @@ struct RegexParser { static let hashtagPattern = "(?:^|\\s|$)#[\\p{L}0-9_]*" static let mentionPattern = "(?:^|\\s|$|[.])@[\\p{L}0-9_]*" static let emailPattern = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" - static let urlPattern = "(^|[\\s.:;?\\-\\]<\\(])" + - "((https?://|www\\.|pic\\.)[-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]+[\\w/#](\\(\\))?)" + - "(?=$|[\\s',\\|\\(\\).:;?\\-\\[\\]>\\)])" + static let urlPattern = "(https?://|www\\.|pic\\.)[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\\-\\._\\?\\,\'/\\\\+&%\\$#\\=~])*" private static var cachedRegularExpressions: [String : NSRegularExpression] = [:] From 58b4354c17d3ee6d1b2b3aef09d866a2d0b8061f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=80=E1=85=AA=E1=86=BC?= =?UTF-8?q?=E1=84=92=E1=85=A7=E1=86=AB?= Date: Sat, 2 Apr 2022 19:59:06 +0900 Subject: [PATCH 2/2] Remove nonexistent file reference --- ActiveLabel.xcodeproj/project.pbxproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ActiveLabel.xcodeproj/project.pbxproj b/ActiveLabel.xcodeproj/project.pbxproj index 2ced28ca..311e4a1c 100644 --- a/ActiveLabel.xcodeproj/project.pbxproj +++ b/ActiveLabel.xcodeproj/project.pbxproj @@ -20,7 +20,6 @@ C1D15C791D7C9B610041D119 /* StringTrimExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D15C781D7C9B610041D119 /* StringTrimExtension.swift */; }; C1D15C7B1D7C9B7E0041D119 /* ActiveBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D15C7A1D7C9B7E0041D119 /* ActiveBuilder.swift */; }; C1E867D61C3D7AEA00FD687A /* RegexParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E867D51C3D7AEA00FD687A /* RegexParser.swift */; }; - CE3BE93D27F4F34D006A3145 /* RegexParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3BE93C27F4F34D006A3145 /* RegexParserTest.swift */; }; E267FA251DB3A34900EEAC4C /* ActiveLabel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8F0249A21B9989B1005D8035 /* ActiveLabel.framework */; }; E267FA261DB3A34900EEAC4C /* ActiveLabel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8F0249A21B9989B1005D8035 /* ActiveLabel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ @@ -75,7 +74,6 @@ C1D15C781D7C9B610041D119 /* StringTrimExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringTrimExtension.swift; sourceTree = ""; }; C1D15C7A1D7C9B7E0041D119 /* ActiveBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActiveBuilder.swift; sourceTree = ""; }; C1E867D51C3D7AEA00FD687A /* RegexParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegexParser.swift; sourceTree = ""; }; - CE3BE93C27F4F34D006A3145 /* RegexParserTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegexParserTest.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -143,7 +141,6 @@ isa = PBXGroup; children = ( 8F0249B11B9989B1005D8035 /* ActiveTypeTests.swift */, - CE3BE93C27F4F34D006A3145 /* RegexParserTest.swift */, 8F0249B31B9989B1005D8035 /* Info.plist */, ); path = ActiveLabelTests; @@ -320,7 +317,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CE3BE93D27F4F34D006A3145 /* RegexParserTest.swift in Sources */, 8F0249B21B9989B1005D8035 /* ActiveTypeTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0;