Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when checking files with accented characters in path #94

Closed
WaveHack opened this issue Nov 4, 2013 · 3 comments
Closed

Error when checking files with accented characters in path #94

WaveHack opened this issue Nov 4, 2013 · 3 comments

Comments

@WaveHack
Copy link

WaveHack commented Nov 4, 2013

When having an accented character in the path of the PHP file which needs checked with PHPCS, PHPCS gives the following error:

 Exception in thread Thread-X:
Traceback (most recent call last):
  File ".\threading.py", line 532, in __bootstrap_inner
  File ".\threading.py", line 484, in run
  File ".\phpcs.py", line 396, in run
  File ".\phpcs.py", line 128, in get_errors
  File ".\phpcs.py", line 344, in execute
  File ".\phpcs.py", line 347, in parse_report
  File ".\phpcs.py", line 149, in shell_out
  File ".\subprocess.py", line 633, in __init__
  File ".\subprocess.py", line 842, in _execute_child
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 43: ordinal not in range(128)

In this case, it's the 'é' in my name in the path where the to-be-checked file resides in.

I managed to fix it like this:

--- phpcs.original.py   Mon Nov  4 11:31:47 2013
+++ phpcs.py    Mon Nov  4 11:22:20 2013
@@ -1,3 +1,4 @@
+import sys
 import datetime
 import os
 import re
@@ -145,6 +146,9 @@
         """
         home = expanduser("~")
         debug_message("cwd: " + home)
+
+        for index, arg in enumerate(cmd[:]):
+            cmd[index] = arg.encode(sys.getfilesystemencoding())

         proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, startupinfo=info, cwd=home)

It works for me (Windows 7), but I can't test it on other OSes.

@benmatselby
Copy link
Owner

Can you provide an example filename please, as it is working on Mac OS X, so potentially just a windows issue. Also, do you want to raise a PR so your name is in the commit log?

@WaveHack
Copy link
Author

WaveHack commented Nov 4, 2013

I have my sublime project in:

C:\Users\René\Dropbox\Development\Personal\Project7\

Example filename I tried to check with PHPCS:

C:\Users\René\Dropbox\Development\Personal\Project7\app\controllers\home.php

It differs slightly, so the exact position on the UnicodeEncodeError could be off. The rest of the error message is still the same, however.

There still seems to be errors when phpcs' show_debug is turned on, which I were unable to fix myself. I'll make the PR in a bit.

@benmatselby
Copy link
Owner

Had to modify the solution ever so slightly, and it is only apparent in ST2, so I wanted to make the fix specific to that, so I know what code I can rip out when I drop support for ST2.

Thanks for the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants