diff --git a/Easydict/App/AppDelegate+EZURLScheme.m b/Easydict/App/AppDelegate+EZURLScheme.m index 33f38332e..eef2674c5 100644 --- a/Easydict/App/AppDelegate+EZURLScheme.m +++ b/Easydict/App/AppDelegate+EZURLScheme.m @@ -89,11 +89,17 @@ - (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEv /** hello, #girl, good - We need to encode the URL to avoid JLRoutes routing failures. + We need to encode the URL to avoid JLRoutes routing failures. PopClip + + --- + + urlString may have been encoded, so we need to check it. + + https://github.com/tisfeng/Easydict/issues/78#issuecomment-1862752708 */ - NSURL *URL = [NSURL URLWithString:urlString.encode]; + NSURL *URL = [NSURL URLWithString:urlString.encodeSafely]; - // easydict://query?text=good + // easydict://query?text=good, easydict://query?text=你好 if ([URL.scheme containsString:EZEasydictScheme]) { NSLog(@"handle URL: %@", URL); } diff --git a/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZConvenience.h b/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZConvenience.h index 71d3c13af..46e19688e 100644 --- a/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZConvenience.h +++ b/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZConvenience.h @@ -34,6 +34,9 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)encode; - (NSString *)decode; +/// Only encode if text has not been encoded. +- (NSString *)encodeSafely; + /// Replace \" with " - (NSString *)escapedXMLString; diff --git a/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZConvenience.m b/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZConvenience.m index 55101679e..9fa469b4c 100644 --- a/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZConvenience.m +++ b/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZConvenience.m @@ -74,6 +74,14 @@ - (NSString *)decode { return decodedText; } +- (NSString *)encodeSafely { + BOOL hasEncoded = ![self.decode isEqualToString:self]; + if (hasEncoded) { + return self; + } + return self.encode; +} + /// Replace \" with " - (NSString *)escapedXMLString { NSString *escapedXMLText = CFBridgingRelease(CFXMLCreateStringByEscapingEntities(NULL, (__bridge CFStringRef)self, NULL));