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

Handle PyYAML ValueError with "._" input #4677

Closed
The-Compiler opened this issue Mar 25, 2019 · 0 comments
Closed

Handle PyYAML ValueError with "._" input #4677

The-Compiler opened this issue Mar 25, 2019 · 0 comments
Labels
bug: exception A Python exception gets thrown. component: config Issues related to configuration. priority: 2 - low Issues which are currently not very important.

Comments

@The-Compiler
Copy link
Member

https://ci.appveyor.com/project/qutebrowser/qutebrowser/builds/23321781/job/rn2uhv74nqup2y7x

__________________ TestAll.test_from_str_hypothesis[klass19] __________________
self = <test_configtypes.TestAll object at 0x000000FAF83F0E80>
klass = functools.partial(<class 'qutebrowser.config.configtypes.List'>, valtype=<qutebrowser.config.configtypes.Url object at 0x000000FADA7F5438>)
    @pytest.mark.usefixtures('config_tmpdir')
>   @hypothesis.given(strategies.text())
    @hypothesis.example('\x00')
    def test_from_str_hypothesis(self, klass, s):
tests\unit\config\test_configtypes.py:219: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests\unit\config\test_configtypes.py:224: in test_from_str_hypothesis
    val = typ.from_str(s)
qutebrowser\config\configtypes.py:476: in from_str
    yaml_val = utils.yaml_load(value)
qutebrowser\utils\utils.py:669: in yaml_load
    data = yaml.load(f, Loader=YamlLoader)
.tox\py37-pyqt512\lib\site-packages\yaml\__init__.py:114: in load
    return loader.get_single_data()
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:43: in get_single_data
    return self.construct_document(node)
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:47: in construct_document
    data = self.construct_object(node)
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:92: in construct_object
    data = constructor(self, node)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <yaml.cyaml.CSafeLoader object at 0x000000FAF357C688>
node = ScalarNode(tag='tag:yaml.org,2002:float', value='._')
    def construct_yaml_float(self, node):
        value = self.construct_scalar(node)
        value = value.replace('_', '').lower()
        sign = +1
        if value[0] == '-':
            sign = -1
        if value[0] in '+-':
            value = value[1:]
        if value == '.inf':
            return sign*self.inf_value
        elif value == '.nan':
            return self.nan_value
        elif ':' in value:
            digits = [float(part) for part in value.split(':')]
            digits.reverse()
            base = 1
            value = 0.0
            for digit in digits:
                value += digit*base
                base *= 60
            return sign*value
        else:
>           return sign*float(value)
E           ValueError: could not convert string to float: '.'
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:284: ValueError
----------------------------- Captured log setup ------------------------------
config.py                  323 DEBUG    Config option changed: aliases = {}
--------------------------------- Hypothesis ----------------------------------
Falsifying example: test_from_str_hypothesis(self=<test_configtypes.TestAll at 0xfaf83f0e80>, klass=functools.partial(<class 'qutebrowser.config.configtypes.List'>, valtype=<qutebrowser.config.configtypes.Url object at 0x000000FADA7F5438>), s='._')
You can reproduce this example by temporarily adding @reproduce_failure('4.12.0', b'AAEAAgEBAAAvAA==') as a decorator on your test case
__________________ TestAll.test_from_str_hypothesis[klass20] __________________
self = <test_configtypes.TestAll object at 0x000000FAF842DB00>
klass = functools.partial(<class 'qutebrowser.config.configtypes.ListOrValue'>, valtype=<qutebrowser.config.configtypes.Int object at 0x000000FADA7F5400>)
    @pytest.mark.usefixtures('config_tmpdir')
>   @hypothesis.given(strategies.text())
    @hypothesis.example('\x00')
    def test_from_str_hypothesis(self, klass, s):
tests\unit\config\test_configtypes.py:219: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests\unit\config\test_configtypes.py:224: in test_from_str_hypothesis
    val = typ.from_str(s)
qutebrowser\config\configtypes.py:569: in from_str
    return self.listtype.from_str(value)
qutebrowser\config\configtypes.py:476: in from_str
    yaml_val = utils.yaml_load(value)
qutebrowser\utils\utils.py:669: in yaml_load
    data = yaml.load(f, Loader=YamlLoader)
.tox\py37-pyqt512\lib\site-packages\yaml\__init__.py:114: in load
    return loader.get_single_data()
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:43: in get_single_data
    return self.construct_document(node)
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:47: in construct_document
    data = self.construct_object(node)
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:92: in construct_object
    data = constructor(self, node)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <yaml.cyaml.CSafeLoader object at 0x000000FAF3579988>
node = ScalarNode(tag='tag:yaml.org,2002:float', value='._')
    def construct_yaml_float(self, node):
        value = self.construct_scalar(node)
        value = value.replace('_', '').lower()
        sign = +1
        if value[0] == '-':
            sign = -1
        if value[0] in '+-':
            value = value[1:]
        if value == '.inf':
            return sign*self.inf_value
        elif value == '.nan':
            return self.nan_value
        elif ':' in value:
            digits = [float(part) for part in value.split(':')]
            digits.reverse()
            base = 1
            value = 0.0
            for digit in digits:
                value += digit*base
                base *= 60
            return sign*value
        else:
>           return sign*float(value)
E           ValueError: could not convert string to float: '.'
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:284: ValueError
----------------------------- Captured log setup ------------------------------
config.py                  323 DEBUG    Config option changed: aliases = {}
--------------------------------- Hypothesis ----------------------------------
Falsifying example: test_from_str_hypothesis(self=<test_configtypes.TestAll at 0xfaf842db00>, klass=functools.partial(<class 'qutebrowser.config.configtypes.ListOrValue'>, valtype=<qutebrowser.config.configtypes.Int object at 0x000000FADA7F5400>), s='._')
You can reproduce this example by temporarily adding @reproduce_failure('4.12.0', b'AAEAAgEBAAAvAA==') as a decorator on your test case
__________________ TestAll.test_from_str_hypothesis[klass21] __________________
self = <test_configtypes.TestAll object at 0x000000FAF8C360B8>
klass = functools.partial(<class 'qutebrowser.config.configtypes.ListOrValue'>, valtype=<qutebrowser.config.configtypes.Url object at 0x000000FADA7F5390>)
    @pytest.mark.usefixtures('config_tmpdir')
>   @hypothesis.given(strategies.text())
    @hypothesis.example('\x00')
    def test_from_str_hypothesis(self, klass, s):
tests\unit\config\test_configtypes.py:219: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests\unit\config\test_configtypes.py:224: in test_from_str_hypothesis
    val = typ.from_str(s)
qutebrowser\config\configtypes.py:569: in from_str
    return self.listtype.from_str(value)
qutebrowser\config\configtypes.py:476: in from_str
    yaml_val = utils.yaml_load(value)
qutebrowser\utils\utils.py:669: in yaml_load
    data = yaml.load(f, Loader=YamlLoader)
.tox\py37-pyqt512\lib\site-packages\yaml\__init__.py:114: in load
    return loader.get_single_data()
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:43: in get_single_data
    return self.construct_document(node)
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:47: in construct_document
    data = self.construct_object(node)
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:92: in construct_object
    data = constructor(self, node)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <yaml.cyaml.CSafeLoader object at 0x000000FAF357F928>
node = ScalarNode(tag='tag:yaml.org,2002:float', value='._')
    def construct_yaml_float(self, node):
        value = self.construct_scalar(node)
        value = value.replace('_', '').lower()
        sign = +1
        if value[0] == '-':
            sign = -1
        if value[0] in '+-':
            value = value[1:]
        if value == '.inf':
            return sign*self.inf_value
        elif value == '.nan':
            return self.nan_value
        elif ':' in value:
            digits = [float(part) for part in value.split(':')]
            digits.reverse()
            base = 1
            value = 0.0
            for digit in digits:
                value += digit*base
                base *= 60
            return sign*value
        else:
>           return sign*float(value)
E           ValueError: could not convert string to float: '.'
.tox\py37-pyqt512\lib\site-packages\yaml\constructor.py:284: ValueError
----------------------------- Captured log setup ------------------------------
config.py                  323 DEBUG    Config option changed: aliases = {}
--------------------------------- Hypothesis ----------------------------------
Falsifying example: test_from_str_hypothesis(self=<test_configtypes.TestAll at 0xfaf8c360b8>, klass=functools.partial(<class 'qutebrowser.config.configtypes.ListOrValue'>, valtype=<qutebrowser.config.configtypes.Url object at 0x000000FADA7F5390>), s='._')
You can reproduce this example by temporarily adding @reproduce_failure('4.12.0', b'AAEAAgEBAAAvAA==') as a decorator on your test case

See yaml/pyyaml#168

@The-Compiler The-Compiler added component: config Issues related to configuration. priority: 2 - low Issues which are currently not very important. bug: exception A Python exception gets thrown. labels Mar 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: exception A Python exception gets thrown. component: config Issues related to configuration. priority: 2 - low Issues which are currently not very important.
Projects
None yet
Development

No branches or pull requests

1 participant