Skip to content

Commit 88ff240

Browse files
committed
fix percent encoding for makeInteract
1 parent ff36376 commit 88ff240

9 files changed

Lines changed: 28 additions & 19 deletions

File tree

AttributedTextView.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'AttributedTextView'
3-
s.version = '0.8.0'
3+
s.version = '0.8.1'
44
s.license = { :type => "MIT", :file => "LICENSE" }
55
s.summary = 'Easiest way to create an attributed UILabel or UITextView (with support for multiple links and HTML)'
66
s.homepage = 'https://github.com/evermeer/AttributedTextView'
@@ -9,6 +9,7 @@ Pod::Spec.new do |s|
99
s.source = { :git => "https://github.com/evermeer/AttributedTextView.git", :tag => "v"+s.version.to_s }
1010
s.platforms = { :ios => "8.0" }
1111
s.requires_arc = true
12+
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.0' }
1213

1314
s.frameworks = "Foundation", "UIKit"
1415
s.source_files = "Sources/*.swift"

AttributedTextView.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@
347347
isa = PBXProject;
348348
attributes = {
349349
LastSwiftUpdateCheck = 0810;
350-
LastUpgradeCheck = 0900;
350+
LastUpgradeCheck = 0930;
351351
ORGANIZATIONNAME = evermeer;
352352
TargetAttributes = {
353353
3549BB201DA389CD00C63030 = {
@@ -538,13 +538,15 @@
538538
CLANG_WARN_BOOL_CONVERSION = YES;
539539
CLANG_WARN_COMMA = YES;
540540
CLANG_WARN_CONSTANT_CONVERSION = YES;
541+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
541542
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
542543
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
543544
CLANG_WARN_EMPTY_BODY = YES;
544545
CLANG_WARN_ENUM_CONVERSION = YES;
545546
CLANG_WARN_INFINITE_RECURSION = YES;
546547
CLANG_WARN_INT_CONVERSION = YES;
547548
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
549+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
548550
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
549551
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
550552
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -599,13 +601,15 @@
599601
CLANG_WARN_BOOL_CONVERSION = YES;
600602
CLANG_WARN_COMMA = YES;
601603
CLANG_WARN_CONSTANT_CONVERSION = YES;
604+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
602605
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
603606
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
604607
CLANG_WARN_EMPTY_BODY = YES;
605608
CLANG_WARN_ENUM_CONVERSION = YES;
606609
CLANG_WARN_INFINITE_RECURSION = YES;
607610
CLANG_WARN_INT_CONVERSION = YES;
608611
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
612+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
609613
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
610614
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
611615
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;

AttributedTextView.xcodeproj/xcshareddata/xcschemes/AttributedTextView-iOS.xcscheme

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "0930"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
language = ""
3029
shouldUseLaunchSchemeArgsEnv = "YES">
3130
<Testables>
3231
<TestableReference
@@ -56,7 +55,6 @@
5655
buildConfiguration = "Debug"
5756
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5857
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
59-
language = ""
6058
launchStyle = "0"
6159
useCustomWorkingDirectory = "NO"
6260
ignoresPersistentStateOnLaunch = "NO"

AttributedTextView.xcodeproj/xcshareddata/xcschemes/AttributedTextView-macOS.xcscheme

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "0930"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
language = ""
3029
shouldUseLaunchSchemeArgsEnv = "YES">
3130
<Testables>
3231
<TestableReference
@@ -56,7 +55,6 @@
5655
buildConfiguration = "Debug"
5756
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5857
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
59-
language = ""
6058
launchStyle = "0"
6159
useCustomWorkingDirectory = "NO"
6260
ignoresPersistentStateOnLaunch = "NO"

AttributedTextView.xcodeproj/xcshareddata/xcschemes/AttributedTextView-tvOS.xcscheme

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "0930"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
language = ""
3029
shouldUseLaunchSchemeArgsEnv = "YES">
3130
<Testables>
3231
<TestableReference
@@ -56,7 +55,6 @@
5655
buildConfiguration = "Debug"
5756
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5857
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
59-
language = ""
6058
launchStyle = "0"
6159
useCustomWorkingDirectory = "NO"
6260
ignoresPersistentStateOnLaunch = "NO"

AttributedTextView.xcodeproj/xcshareddata/xcschemes/AttributedTextView-watchOS.xcscheme

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "0930"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,7 +26,6 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
language = ""
3029
shouldUseLaunchSchemeArgsEnv = "YES">
3130
<Testables>
3231
</Testables>
@@ -37,7 +36,6 @@
3736
buildConfiguration = "Debug"
3837
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3938
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
40-
language = ""
4139
launchStyle = "0"
4240
useCustomWorkingDirectory = "NO"
4341
ignoresPersistentStateOnLaunch = "NO"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Demo/ViewController.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class ViewController: UIViewController {
5959
}.underline
6060
.append(" for testing links. Or tap on the 'next sample' link below ").black
6161
.underline(.styleDouble, .patternDashDotDot)
62+
.append("[test]").makeInteract { text in
63+
print("makeInteract : \(text)")
64+
}
6265
}
6366
.all.font(UIFont(name: "SourceSansPro-Regular", size: 16)) // Font not availabel in this demo...
6467
.setLinkColor(UIColor.purple) // Will be set on the control so we also have to reset it when we show the next sample.

Sources/Attributer.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,11 @@ open class Attributer {
528528
open func makeInteract(_ callback: @escaping ((_ link: String) -> ())) -> Attributer {
529529
for nsRange in self.ranges {
530530
let iRange = self.attributedText.string.range(from: nsRange)
531-
if let escapedString = self.attributedText.string.substring(with: iRange!).addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlHostAllowed) {
531+
let unEscapedString = self.attributedText.string.substring(with: iRange!)
532+
let escapedString = unEscapedString.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlHostAllowed) ?? ""
532533
self.attributedText.addAttribute(NSAttributedStringKey.link, value: "AttributedTextView:\(escapedString)", range: nsRange)
533-
urlCallbacks[escapedString] = callback
534-
}
534+
urlCallbacks[unEscapedString] = callback
535+
535536
}
536537
return self
537538
}
@@ -552,8 +553,8 @@ open class Attributer {
552553
-parameter URL: The URL that was touched
553554
*/
554555
public func interactWithURL(URL: URL) {
555-
let escapedString = URL.absoluteString.replacingOccurrences(of: "AttributedTextView:", with: "")
556-
urlCallbacks[escapedString]?(escapedString)
556+
let unescapedString = URL.absoluteString.replacingOccurrences(of: "AttributedTextView:", with: "").removingPercentEncoding ?? ""
557+
urlCallbacks[unescapedString]?(unescapedString)
557558
}
558559

559560
/**

0 commit comments

Comments
 (0)