Giter VIP home page Giter VIP logo

idna-cocoa's Introduction

IDNA Cocoa

v2.0b4 (2021) by Nate Weaver (Wevah)
https://derailer.org/
https://github.com/Wevah/Punycode-Cocoa

Swift

An IDNA String extension and NSString overlay, based on UTS #46. Currently implents the full conversion table and joiner validation.

Use this to convert internationalized domain names (IDN) between Unicode and ASCII.

To use in your own projects, this repository can be imported as a Swift package.

Alternatively, the files can be manually included: Everything in Sources/IDNA:

  • UTS46.swift
  • UTS46+Loading.swift
  • Data+Extensions.swift
  • Scanner+Extensions.swift
  • String+Punycode.swift

If your project needs to call from Objective-C make sure to include NSString+IDNA.swift for the NSString overlays.

(UTS46+Conversion.swift is for importing text files containing UTS #46 mappings and exporting to the binary format used by UTS46+Loading.swift, and isn't necessary if you just want to use the encoding/decoding routines.)

Note that these API currently don't do homograph detection.

Interface

String/NSString

Swift:
var idnaEncoded: String? { get }
Objective-C:
@property (readonly, copy, nullable) NSString *IDNAEncodedString;

If self contains non-ASCII, encodes the string's domain components as Punycode and prepends xn-- to the transformed components.


Swift:
var idnaDecoded: String? { get }
Objective-C:
@property (readonly, copy, nullable) NSString *IDNADecodedString;

Decodes a string returned by idnaEncoded/-IDNAEncodedString.


Swift:
var encodedURLString: String? { get }
var decodedURLString: String? { get }
Objective-C:
@property (readonly, copy, nullable) NSString *encodedURLString;
@property (readonly, copy, nullable) NSString *decodedURLString;

Performs Punycode encode/decode operations on each appropriate part (the domain bits) of an URL string, and URL encodes/decodes the path/query/fragment.


URL/NSURL

Swift:
init?(unicodeString: String)
Objective-C:
+ (nullable instancetype)URLWithUnicodeString:(NSString *)URLString;

Convenience initializer equivalent to URL(string: unicodeString.encodedURLString)/ [NSURL URLWithString:URLString.encodedURLString].


Swift:
var decodedURLString: String? { get }
Objective-C:
@property (readonly, copy, nullable) NSString *decodedURLString;

Convenience property equivalent to someURL.absoluteString.decodedURLString.


Swift:
init?(unicodeString: String, relativeTo url: URL?) {
Objective-C:
+ (nullable instancetype)URLWithUnicodeString:(NSString *)URLString relativeToURL:(nullable NSURL *)baseURL;

Convenience initializer for creating a URL from a Unicode string, relative to another URL.


© 2012–2022 Nate Weaver (Wevah)

idna-cocoa's People

Contributors

jhammer avatar notjosh avatar orkoden avatar wevah avatar wirthcaesar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

idna-cocoa's Issues

Can't compile for iOS 9.3

This might be toolchain bug, but I figured I'd mention it here just in case you have any ideas.

I can no longer build my app that targets iOS 9.3, where I used to be able to

URL+Encode.swift:2:8: error build: Compiling for iOS 9.3, but module 'IDNA' has a minimum deployment target of iOS 11.0: <>/Build/Products/Debug-iphoneos/IDNA.swiftmodule/arm64-apple-ios.swiftmodule

I'm pinned to commit 3f769fd, but also tried 1f18874.

I see that the package specifically supports iOS 9 in the Package.swift file.

Xcode 4.5 Warnings

NSStringPunycodeAdditions.m:119:25: Format specifies type 'unsigned short' but the argument has type 'UTF32Char' (aka 'unsigned long')
NSStringPunycodeAdditions.m:128:24: Format specifies type 'unsigned short' but the argument has type 'int'
NSStringPunycodeAdditions.m:159:27: Format specifies type 'unsigned short' but the argument has type 'char'
NSStringPunycodeAdditions.m:163:26: Format specifies type 'unsigned short' but the argument has type 'char'

Incorrect punycodes for emoji?

I'm trying to encode emoji like 😀 and ⬛️ to punycode.

I noticed that Safari (and this converter) encode some emoji differently than the library. Is this a bug causing something extra to get appended or is it just a disparity in encodings?

Emoji Safari Punycode-Cocoa
😀 xn--e28h xn--e28h
⬛️ xn--w5i xn--w5ix313e
▪️ xn--30h xn--30h0620f

URLParts -> NSURLComponents

I think you'll have slightly less janky code if you use NSURLComponents to digest a particular url into its components rather than scanning through strings for separator characters.

Use URLComponents on Ventura+

URLComponents on Ventura and up properly encode the host using Punycode (Monterey and under incorrectly percent-encode/decode the host parts).

Note: URL on Sonoma and up (will) directly support Punycoding also, but IDNA-Cocoa already tries URL first, so no changes need to be made there.

Missing tag 2.0 for Punycode-Cocoa.podspec

The podspec for v2.0 was released earlier, but there is no "2.0" tagged commit.
So I can't use v2.0 Punycode-Cocoa.
And v1.3.1 is the latest version release of CocoaPod.

I would expect v2.0 to be available on a cocoapod or to be resolved tagging problem.

I have been using punycode-ccocoa well and it is very much appreciated.

Swift package

With the ability to add resources to Swift packages, this is now possible.

Xcode 9 Warning

Xcode 9 warns about Possible misuse of comma operator here:

NSStringPunycodeAdditions.m on line 206:

++delta, ++n;

encodedURLString issue

Hello again!

encoded to

becouse stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding return nil in encodedURLString.
For what need:

NSString *path = [[[urlParts objectForKey:@"path"] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

instead:

NSString *path = [urlParts objectForKey:@"path"];

?

Deprecated API

Methods CFURLCreateStringByAddingPercentEscapes and stringByReplacingPercentEscapesUsingEncoding are deprecated in iOS 9. Is it possible to update the code so that it won't generate warnings?

"Fragment" portion not URL Encoded

I'm not sure if this is part of RFC 3492 and RFC 3490, but I've encountered it in my own code.

For example, if I go to google and search for "渋谷" it will send me to something like
https://www.google.co.jp/webhp?<stuff>#q=%E6%B8%8B%E8%B0%B7

But if I put in https://www.google.co.jp/webhp?<stuff>#q=渋谷 into Punycode-Cocoa's + (NSURL *)URLWithUnicodeString:(NSString *)URLString;, it will return nil.

This can easily be solved by just URL encoding the fragment here.

What do you think, would there be any problem with other URLs by adding this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.