Skip to content

Commit

Permalink
Merge pull request #41 from eliangcs/issues/39-non-ascii
Browse files Browse the repository at this point in the history
Fix #39: non-ascii character issue on Python 2
  • Loading branch information
eliangcs committed Jun 2, 2016
2 parents b183bac + c6d7570 commit 8fd2b6b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion http_prompt/completer.py
@@ -1,3 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import re
import six

Expand Down Expand Up @@ -41,7 +44,8 @@ def compile_rules(rules):
def fuzzyfinder(text, collection):
"""https://github.com/amjith/fuzzyfinder"""
suggestions = []
text = str(text) if not isinstance(text, str) else text
if not isinstance(text, six.text_type):
text = six.u(text, 'utf-8')
pat = '.*?'.join(map(re.escape, text))
regex = re.compile(pat, flags=re.IGNORECASE)
for item in collection:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_completer.py
@@ -1,3 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import six
import unittest

Expand Down Expand Up @@ -58,3 +61,11 @@ def test_rm_option(self):
self.context.options['--form'] = None
result = self.get_completions('rm -o ')
self.assertEqual(result[0], '--form')

def test_querystring_with_chinese(self):
result = self.get_completions('name==王')
self.assertFalse(result)

def test_header_with_spanish(self):
result = self.get_completions('X-Custom-Header:Jesú')
self.assertFalse(result)
15 changes: 15 additions & 0 deletions tests/test_execution.py
@@ -1,3 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import unittest

import pytest
Expand Down Expand Up @@ -268,6 +271,12 @@ def test_querystring_with_single_quotes(self):
'name': 'John Doe'
})

def test_querystring_with_chinese(self):
execute("name==王小明", self.context)
self.assertEqual(self.context.querystring_params, {
'name': '王小明'
})

def test_simple_body_params(self):
execute('username=john password=123', self.context)
self.assertEqual(self.context.body_params, {
Expand Down Expand Up @@ -296,6 +305,12 @@ def test_body_param_with_double_quotes(self):
'password': '123'
})

def test_body_param_with_spanish(self):
execute('name=Jesús', self.context)
self.assertEqual(self.context.body_params, {
'name': 'Jesús'
})

def test_long_option_names(self):
execute('--auth user:pass --form', self.context)
self.assertEqual(self.context.options, {
Expand Down

0 comments on commit 8fd2b6b

Please sign in to comment.