Repository navigation
Conversation
|
This fix will result in sed being run with a different locale than the rest of the function, since you're not exporting LC_ALL. I'm not sure if that can cause issues, though. |
|
UTF-8 is ASCII compatible. |
|
UTF-8 is ASCII-compatible for those characters that are in ASCII, and then only if you ignore the 8th bit (which pretty much everyone does nowadays). But that doesn't quite answer the question. Is there a failure case? Thinking further about it, sed isn't the issue - printf is. Can that deal with getting incomplete UTF-8 characters? Because it'll be running in a UTF-8 locale. And since "Ä" is already two-byte, it apparently can. I still don't quite like the solution here, but it's probably necessary since Terminal.app seems to expect it that way. Does it break any other terminals that use this function? |
|
Thanks for the notice. I've checked the source code of the builtin
|
|
Though it's weird that in #2598, Builtin printf is an import of a rather old version of GNU printf, IIRC, so it's possible there's bugs _there. Could you check if it works with a new GNU printf as well? |
|
Sorry, I gave the wrong evidence above. But I believe that the POSIX stardard allowed locale "C" to deal with UTF-8 strings. I'll look into the source code again later. |
|
For your concerns about the BSD one: |
|
No, I've said that his code causes problems (with the gnu one on my mac). The original one used in the repo is the builtin. |
|
Using |
|
The warnings from the newer GNU printf on my mac are caused by |
|
I've modified the patch, also make the code more readable and forward-compatible (although fish is using a modified version of the gnu printf). New GNU printf manual: http://www.gnu.org/software/coreutils/manual/html_node/printf-invocation.html
The corresponding source code of the builtin printf: fish-shell/src/builtin_printf.cpp Lines 251 to 305 in c1bd3b5 |
|
For other terminals (VTE-based, gnome-terminal in #906), I think the builtin printf does not care about locale when getting the scalar value from a wide character. So we must know the spec of the file URI. I guess it is in https://en.wikipedia.org/wiki/File_URI_scheme ?? |
|
Changed again for dealing with NUL and EOL. |
|
Can anyone with access to Terminal.app test this? @ridiculousfish? |
|
@faho I've confirmed that the problem exists without this change and does not exist with it applied on Mac OS X 10.11.2 (the most recent version available). But there is a bug. Note that the Notice that after invoking |
Wow! That deserves its own issue I think.
I do believe so.
Most likely the better solution - it also seems that it won't add the export bit, so it seems safe. @jakwings? |
|
IFS and many other variables are affected too! Let's wait until that bug is fixed. |
In theory, yes. In practice, no, because the other vars you're touching aren't exported except by people who don't know what they're doing.
I don't see why this shouldn't be merged once my recommendation is added to the PR. Should LANG continue to be exported even though you did not include the -x option? Should your making a local change without explicitly saying the new value should be exported result in the var not being exported to any external command? If the answer is yes then external commands won't get the LANG setting in effect for the shell. That seems like a bug to me. Alternatively, we can define the semantics to be that the pre-existing value is still exported to external commands and the |
|
Hmm..Only the builtin Changed to |
|
Wait, I met this warning after this Diaeresis (0x308, |
|
No, I just checked every The single quote to used to turn |
There wouldn't be since the od command explicitly uses the C locale in order to operate on individual bytes. So it can't recognize values above 255 decimal by design. Somewhere in your data there is a Unicode code point with value 776. The question is which fish command is being fed a non-ASCII value with LC_ALL=C. |
|
Some tests:
I'm confused... |
|
Yes, you are confused :-) The od command shows "multiple bytes" but does not recognize values greater than a single eight-bit byte (decimal 255). That means it cannot, by definition, show a value with a decimal value of 776. You seem to be confusing bytes with characters (chars). The od command does not use or recognize any character encoding. The od command by design ignores the LANG/LC_ALL setting. P.S. I'm obviously ignoring atypical systems like very old Honeywell computers which had a 9-bit byte. Or CDC Cyber super computers with a 60-bit word length. Such systems are not relevant to this issue. |
|
The simple tests above are not related to Not sure if we are talking about the same version of If there is 776, I think there could be two bytes: |
|
So now there are at least two problems about the exported variables. Well, I've done it in another way. I will commit later, maybe until the bugs are fixed. |
|
Updated (rebased, so unfortunately two code comments from @krader1961 are flushed away). As the original script does, the printf format |
|
ohmyzsh/ohmyzsh#3582 uses |
|
@jakwings: Do you still care about getting this change merged? |
|
@krader1961 What about issue #2611? |
|
Issue #2611 is really orthogonal to your change since you should be explicitly exporting the var rather than relying on the nested context inheriting the export bit. |
|
No, I'm not relying on the export bit (especially IFS). As I pointed out in a comment above, either If it was just that easy by exporting variables, we could have solved this problem ~2 months ago. |
|
Notes (because @krader1961's comments in the code review were flushed away after a git rebase): Environment variables LC_ALL and IFS are intended to be used only by the builtin function |
|
Nowhere did I suggest exporting IFS; only LC_ALL to work around issue #2611. IFS, despite the all-caps name, should not be exported as it is private to the current shell session. The "no narrow representation" warning message only occurs when an environment var (such as $PWD) has a character whose codepoint is greater than 255 (i.e., a non ISO-8859 char) and you spawn an external command. In other words, you can't start fish in a UTF-8 locale, create an env var with a non-ISO-8859 char, then switch to a ISO-8859/ASCII/C locale. Which is basically what your fix is doing. The problem is that exporting LC_ALL=C once PWD contains /tmp/Äpfel causes the printf subcommand pipeline in to spawn a fish shell with LC_ALL=C. Since the $PWD environment contains unicode "wide" chars the shell complains when trying to serialize the "wide" character (i.e., the unicode combining diaeresis 776 or 0x308) to a single byte for export as required by LC_ALL=C. You can't change the encoding to C (or other ISO-8859 encoding) once a non-ISO-8859 character is captured in an environment var because the char has already been encoded as a "wide" character. This fix is fundamentally flawed irrespective of issue #2611. Whether or not this can be fixed in the __fish_urlencode function without deeper changes to the fish implementation is TBD. |
|
Also note that the function we're discussing is used in exactly one place in the fish source: setting the title of the Apple Terminal session. Which is not to imply fixing this is unimportant. However, fixing this doesn't necessarily have to be done using the bare minimum of non-fish commands. In other words, using something like a python script to url-encode the unicode string might be acceptable. |
* When using a UTF-8 locale, set locale to C temporarily in order to read one byte at a time. * Use the builtin printf in a forward-compatible way. (GNU) * Improve the readability of the code.
|
You're right, LC_ALL can pollute other processes in that damn posix way. After grepping LC_ and IFS in the repo, I see that LC_* hardly appear, so I should use a more conservative method (wrapping read in |
Not sure what you're asking. The -x shouldn't be necessary and doesn't do anything in this situation other than workaround a bug. Including it is "more correct" in so far as you would normally export it so that subshells from Also, nice trick leveraging a |
|
Yep, -x is just a workaround here. |
|
@jakwings do you, or anyone else, have an objection to merging this? Looks good to me. |
|
@krader1961 No. This is by far the simplest resolution. If code comment is needed, please add it anyway. |
|
Thanks. Merged as squashed commit 1c8c297. |
|
@krader1961 Are you sure you are not merging the latest patch? That looks like my very first submit. |
|
I had not seen this before, but this function as written is really strange. It's hex-encoding everything, and then de-encoding Personally, I'm also in favor of only hex-encoding the bytes that need to be hex-encoded, but that does mean building up the string character-by-character instead of using one invocation of From my own local fish config, here's the function I'm using to urlencode. It doesn't touch # Percent-encode the path
set -l url_path ''
set -l IFS ''
printf '%s' $PWD | read -alz chars
for c in $chars
if string match -q -r '[/._~A-Za-z0-9-]' $c
set url_path $url_path$c
else
set url_path (printf '%s%%%02X' $url_path "'$c")
end
end |
|
@jakwings: Yeah, I screwed up the merge. I think I've fixed it. Please check. |
|
@kballard, |
|
I use a kballard-inspired function locally, so as not to percent-encode the ASCII, works here: function __fish_urlencode --description "URL-encode stdin"
set -l chars
# Set locale to C and IFS to "" in order to split a line into bytes.
while begin; set -lx LC_ALL C; set -lx IFS ''; read --array chars; end
if count $chars > /dev/null
for c in $chars
if string match -q -r '[/._~A-Za-z0-9-]' $c
printf $c
else
printf '%%%02X' "'$c"
end
end
end
end
end |


Steps to reproduce the problem (locale is
en_US.UTF-8):mkdir Äpfelcd ÄpfelSolution: Set locale to C in order to read one byte at a time, so the expected output
%XXdoes not become%XXXor%XXXX.