# Buggy code
def _unescape_str(text):
    """
    Unescapes a string according the TOML spec. Raises BadEscapeCharacter when appropriate.
    """

    # Detect bad escape jobs
    bad_escape_regexp = re.compile(r'([^\\]|^)\\[^btnfr"\\uU]')
    if bad_escape_regexp.findall(text):
        raise BadEscapeCharacter

    # Do the unescaping
    if six.PY2:
        return (
            _unicode_escaped_string(text)
            .decode("string-escape")
            .decode("unicode-escape")
        )
    else:
        return codecs.decode(_unicode_escaped_string(text), "unicode-escape")


# Traceback (prettytoml.tokens.error)
Requirements file provided! Importing into Pipfile...
Traceback (most recent call last):
File "/usr/bin/pipenv", line 11, in <module>
load_entry_point('pipenv==2018.7.1', 'console_scripts', 'pipenv')()
File "/usr/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/pipenv/cli.py", line 435, in install
selective_upgrade=selective_upgrade,
File "/usr/lib/python3.7/site-packages/pipenv/core.py", line 1890, in do_install
section = project.editable_packages if not dev else project.editable_dev_packages
File "/usr/lib/python3.7/site-packages/pipenv/project.py", line 524, in editable_packages
return self._get_editable_packages(dev=False)
File "/usr/lib/python3.7/site-packages/pipenv/project.py", line 508, in _get_editable_packages
for k, v in self.parsed_pipfile.get(section, {}).items()
File "/usr/lib/python3.7/site-packages/pipenv/project.py", line 509, in <dictcomp>
if is_editable(v)
File "/usr/lib/python3.7/site-packages/pipenv/utils.py", line 584, in is_editable
pipfile_entry.get(key) for key in ('file', 'path') + VCS_LIST
File "/usr/lib/python3.7/site-packages/pipenv/utils.py", line 584, in <genexpr>
pipfile_entry.get(key) for key in ('file', 'path') + VCS_LIST
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/elements/abstracttable.py", line 73, in get
return self[key]
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/elements/abstracttable.py", line 66, in __getitem__
for key, value in self.items():
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/elements/abstracttable.py", line 34, in items
yield key.value, value.value
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/elements/atomic.py", line 40, in value
return toml2py.deserialize(self._tokens[self._value_token_index()])
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/tokens/toml2py.py", line 33, in deserialize
return _to_string(token)
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/tokens/toml2py.py", line 86, in _to_string
return _unescape_str(escaped)
File "/usr/lib/python3.7/site-packages/pipenv/patched/prettytoml/tokens/toml2py.py", line 46, in _unescape_str
raise BadEscapeCharacter
prettytoml.tokens.errors.BadEscapeCharacter

# Fixed code
def _unescape_str(text):
    """
    Unescapes a string according the TOML spec. Raises BadEscapeCharacter when appropriate.
    """
    text = text.decode("utf-8") if isinstance(text, six.binary_type) else text
    tokens = []
    i = 0
    basicstr_re = re.compile(r'[^"\\\000-\037]*')
    unicode_re = re.compile(r"[uU]((?<=u)[a-fA-F0-9]{4}|(?<=U)[a-fA-F0-9]{8})")
    escapes = {
        "b": "\b",
        "t": "\t",
        "n": "\n",
        "f": "\f",
        "r": "\r",
        "\\": "\\",
        '"': '"',
        "/": "/",
        "'": "'",
    }
    while True:
        m = basicstr_re.match(text, i)
        i = m.end()
        tokens.append(m.group())
        if i == len(text) or text[i] != "\\":
            break
        else:
            i += 1
        if unicode_re.match(text, i):
            m = unicode_re.match(text, i)
            i = m.end()
            tokens.append(six.unichr(int(m.group(1), 16)))
        else:
            if text[i] not in escapes:
                raise BadEscapeCharacter
            tokens.append(escapes[text[i]])
            i += 1
    return "".join(tokens)