Repository: RocketMap/RocketMap

Issue:
If path includes non-ASCII character, several things break (eg icon display)
if the installation path includes a non-ASCII character, the function to deliver the icons/sprites/images fails. 

## Expected Behavior
path should work independently of non-ASCII characters

## Current Behavior
no images get displayed

## Possible Solution
possibly use functions that are UTF-8 safe

## Steps to Reproduce (for bugs)
install RM into a path like $HOME/Pokémon/RocketMap and see what happens.

## Context
<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world -->

## Your Environment
* Version used: latest version from git
* Environment name and version (e.g. Python 2.7): python 2.7
* Operating System and version (desktop or mobile): ubuntu 16.04 server



Discussion:
This not a RocketMap-specific issue, it's an issue with how Flask handles serving files from the static directory.

Same as [issue](https://github.com/git-cola/git-cola/issues/551) (with [fix](https://github.com/git-cola/git-cola/commit/5b389a18b582ef8b51a1d306fc27bc070b807245)). The sys.setdefaultencoding() hack used here is [advised against](https://anonbadger.wordpress.com/2015/06/16/why-sys-setdefaultencoding-will-break-code/).

Suggested alternative solutions:
1. Don't run RocketMap from a directory with a non-ascii path
2. Use Apache/Nginx etc. to serve static content
If we would do anything here, it would be to terminate if a non-ascii path is detected, to keep consistent with the logging system that requires characters/numbers that can pass python's .alnum() in status name.

edit: Didn't research last night that Flask supported UTF-8, in that case if support can be added then it shall be
Maybe add a note to the installation instructions?


On Thu, Aug 3, 2017 at 10:24 AM, FrostTheFox <notifications@github.com>
wrote:

> If we would do anything here, it would be to terminate if a non-ascii path
> is detected, to keep consistent with the logging system that requires
> characters/numbers that can pass python's .alnum() in status name.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/RocketMap/RocketMap/issues/2226#issuecomment-319902854>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ADp0pTBapsn8qVnYGdMArgH40racRe23ks5sUYPTgaJpZM4OrruD>
> .
>



-- 
Axel Eble * Schützenallee 70 * 79102 Freiburg * Germany * cell:
+49.178.285-3265

@pogo-excalibur [Flask supports Unicode/UTF-8](http://flask.pocoo.org/docs/0.12/unicode/), so I think this is a pretty solvable issue. We just need to make sure the strings we use are unicode strings, not ASCII strings (= Py2.7's default).
@sebastienvercammen Unfortunately the issue experienced here is entirely in Flask code - specifically the code Flask uses to serve requests from the static/ directory. There's no code within RM to 'fix'.

Example error dump:
```
[2017-08-03 18:55:21,274] ERROR in app: Exception on /static/images/rocket.png [GET]
Traceback (most recent call last):
  File "<PYTHON>/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "<PYTHON>/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "<PYTHON>/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "<PYTHON>/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "<PYTHON>/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "<PYTHON>/site-packages/flask_cache_bust/__init__.py", line 57, in debusting_static_view
    return original_static_view(filename=unbust_filename(filename))
  File "<PYTHON>/site-packages/flask/helpers.py", line 892, in send_static_file
    cache_timeout=cache_timeout)
  File "<PYTHON>/site-packages/flask/helpers.py", line 633, in send_from_directory
    filename = safe_join(directory, filename)
  File "<PYTHON>/site-packages/flask/helpers.py", line 603, in safe_join
    return os.path.join(directory, filename)
  File "<PYTHON>/posixpath.py", line 73, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 24: ordinal not in range(128)
```
@pogo-excalibur Perhaps it can be resolved by explicitly passing `root_path` as a Unicode string when initializing Flask.

Resolving patch:
diff --git a/runserver.py b/runserver.py
--- a/runserver.py
+++ b/runserver.py
@@ -258,7 +258,7 @@ def main():
 
     app = None
     if not args.no_server and not args.clear_db:
-        app = Pogom(__name__)
+        app = Pogom(__name__, root_path=os.path.dirname(__file__))
         app.before_request(app.validate_request)
         app.set_current_location(position)
 


Test patch: