iPhone: Invalid Characters in filesystem - iphone

is the iPhone's filesystem or the use of NSFilemanager restricted to any characters or is everything allowed (this is what I'm currently assuming after doing some research).

iPhone OS is derived from BSD. Thus as in other Unix'es the only characters forbidden in individual path elements are '/' and obviously '\0'. Everything else is allowed.

Related

Removing folders with "bad" names on GitHub

I did not realize that certain characters were not allowed for folder names on github and named a couple of folders with the character ":". I cannot figure out how to rename/delete these folders. I don't care about the data inside, I can just reupload.
Anyone know how to fix this?
In general, Git is capable of handling arbitrary byte sequences in file names because it's designed for Unix systems. That means any character except forward slash or NUL can appear in a path component, including characters such as 0xfe and 0xff, which are not valid UTF-8. Colons are one of those permitted characters.
GitHub also does not have a problem with arbitrary bytes. However, if the path isn't valid UTF-8, it might not be rendered properly in the web interface, although it should still be supported via operations with Git.
However, there are some operating systems which are less capable. For example, Windows excludes many common punctuation characters from permissible file names. As a result, you may wish to be kind to users of those operating systems and not use file names that cause problems there.
Since you're on Windows, you'll have some trouble checking out the repository. The best thing to do is clone the repository on a Linux system or under Windows Subsystem for Linux and then rename the files or directories with git mv, then commit and push. macOS should also be able to handle colons in path names, although it requires that the path names be valid UTF-8.

Google Cloud Storage not handling UTF-8 filenames

I am serving files from Google Cloud Storage and some of the filenames contain non-ASCII, UTF-8 encoded characters. For example, volvía.mp3.
If I request volvía.mp3, GCS throws an error.
If I percent encode the filename (í = %C3%AD) as volv%C3%AD.mp3, it still fails.
If I percent encode the filename using the "combining acute accent" = %CC%81 as volvi%CC%81a.mp3, it succeeds.
Any ideas what is going on?
EDIT: The error it throws is an "Access Denied" error:
Anonymous users does not have storage.objects.get access to object. However, this seems to be the error one gets when requesting an object that's not found.
The problem is due Mac OS's HFS+ file system, which enforces canonical decomposition (NFD) on filenames. This means it normalizes characters such as í into two code points (i + combining acute accent) rather than the single code point that is used in "composed" forms, ie., NFC).
GCS treats these two different forms as distinct filenames, despite that fact that they appear identical.
One solution is to convert NFD filenames to the more common NFC forms (using a utility such as convmv) before uploading to GCS. However, this can't be done on Mac OS because the file system itself enforces NFD.
I was not able to reproduce your issue. I uploaded an object named volvía.mp3 and was able to retrieve it as both http://storage.googleapis.com/bucketname/volvía.mp3 and http://storage.googleapis.com/bucketname/volv%C3%ADa.mp3
I suspect that you actually created an object with the "combining acute accent" character instead. How did you upload your object?

How to handle spectial characters in Tritium

I'm working on a Spanish site using MoovWeb & Tritium but I am having issues with special characters.
For a content, wherever there are special characters, it always jumbles them up and show blocks or question-mark character. I don't have access to the source code of original site so I cannot determine if the site was using proper HTML-safe alternatives for special characters.
Is there any way to manage or handle special characters in tritium easily instead of doing some kind of find & replace routine?
While developing locally, you will have the source of the original site in the tmp/messages directory of your project. This is the raw response from the origin server, so any special encoding or character bytes will be preserved. If you can determine the bytes that make up the special characters, you can use Tritium's replace() function to change these bytes to HTML-safe alternatives. For example,
replace(/\xe9/, "é")
where \xe9 is the byte sequence for é.
This is assuming that this character was encoded properly. If not, you'll have to isolate the malformed bytes and replace those one by one.

NSStrings, C strings, pathnames and encodings in iPhone

I am using libxml2 in my iPhone app. I have an NSString that holds the pathname to an XML file. The pathname may include non-ASCII characters. I want to get a C string representation of the NSString for to pass to xmlReadFile(). It appears that cStringUsingEncoding gives me the representation I seek. I am not clear on which encoding to use.
I wonder if there is a "default" encoding in iPhone OS that I can use here and ensure that I can roundtrip non-ASCII pathnames.
Use NSString's fileSystemRepresentation. If the string contains characters that are not representable in the file system's encoding then this method will raise an exception.
To convert back, use NSFileManager's stringWithFileSystemRepresentation:length:

Tilde in device name causing problems with NSOutputStream socket

In the networking between the iPhone and desktop versions of our application, the iPhone sends over the device name for use on the desktop. The problem is that some of the beta testers have tildes (`) in their device names. For some reason when this is in the device name it prevent the socket from sending the actual string data.
I've tried simply cleaning up the device name before sending it, but the tilde in the device name (as entered in iTunes) is not recognized at runtime as a tilde. Here's the code that doesn't work:
NSString *safedevicename = [[UIDevice currentDevice] name];
safedevicename = [safedevicename stringByReplacingOccurrencesOfString:#"`" withString:#"'"];
It finds no occurrences of a tilde, and replaces nothing. I've also used rangeOfString to search for tildes and it returns nothing. I'm 100% sure the character, at least as it's entered in iTunes, is a tilde.
Also, when printing a description of the string to the console, the character is encoded as \u00b4, and when hovering over the variable it appears as a period ..
Anyone know how I can grab this character and get it out of there? Also, isn't there a way in objective C to more easily clean up the string to make sure it's safe to send over a socket?
EDIT:
Also something that might be useful, to write the NSString to the NSOutputString I use the following line of code:
len = [oStream write:[[writeString dataUsingEncoding:NSASCIIStringEncoding] bytes] maxLength:[writeString lengthOfBytesUsingEncoding:NSASCIIStringEncoding]];
EDIT #2:
This line of code works to replace the Tilde, but I'm sure there are other characters I should be worrying about:
safedevicename = [safedevicename stringByReplacingOccurrencesOfString:#"\\u00b4" withString:#"'"];
Jason's comment was the correct answer: I needed to change the encoding from NSASCIIStringEncoding to NSUTF8StringEncoding.