Projet

Général

Profil

0001-misc-don-t-expose-extra-keys-with-invalid-format-as-.patch

Frédéric Péters, 22 avril 2021 14:28

Télécharger (3,11 ko)

Voir les différences:

Subject: [PATCH] misc: don't expose extra keys with invalid format as
 variables (#53345)

 tests/test_formdata.py | 20 +++++++++++---------
 wcs/variables.py       |  3 ++-
 2 files changed, 13 insertions(+), 10 deletions(-)
tests/test_formdata.py
2635 2635
        'type': 'formula',
2636 2636
        'value': repr(
2637 2637
            [
2638
                {'id': '1', 'text': 'un', 'more': 'foo', 'url': 'xxx'},
2639
                {'id': '2', 'text': 'deux', 'more': 'bar', 'url': 'yyy'},
2638
                {'id': '1', 'text': 'un', 'more': 'foo', 'url': 'xxx', 'invalid:key': 'xxx'},
2639
                {'id': '2', 'text': 'deux', 'more': 'bar', 'url': 'yyy', 'invalid:key': 'yyy'},
2640 2640
            ]
2641 2641
        ),
2642 2642
    }
......
2680 2680
        tmpl = Template('{% for x in form_var_plop_structured %}{{x.more}}{% endfor %}')
2681 2681
        assert tmpl.render(context) == 'foobar'
2682 2682

  
2683
    assert 'form_var_plop_0_url' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
2684
    assert 'form_var_plop_1_more' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
2685
    assert 'form_var_plop_structured' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
2686
    assert 'form_var_plop_raw' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
2683
    flat_keys = pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
2684
    assert 'form_var_plop_0_url' in flat_keys
2685
    assert 'form_var_plop_1_more' in flat_keys
2686
    assert 'form_var_plop_structured' in flat_keys
2687
    assert 'form_var_plop_raw' in flat_keys
2688
    assert 'form_var_plop_0_invalid:key' not in flat_keys
2687 2689

  
2688
    assert 'form_var_plop2' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
2689
    assert 'form_var_plop2_raw' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
2690
    assert 'form_var_plop2_structured' in pub.substitutions.get_context_variables(mode='lazy').get_flat_keys()
2690
    assert 'form_var_plop2' in flat_keys
2691
    assert 'form_var_plop2_raw' in flat_keys
2692
    assert 'form_var_plop2_structured' in flat_keys
2691 2693

  
2692 2694

  
2693 2695
def test_formdata_user_field(pub, variable_test_data):
wcs/variables.py
804 804
        def walk(base, value):
805 805
            if isinstance(value, dict):
806 806
                for k, v in value.items():
807
                    walk(k if not base else base + '_' + k, v)
807
                    if CompatibilityNamesDict.valid_key_regex.match(k):
808
                        walk(k if not base else base + '_' + k, v)
808 809
            else:
809 810
                keys.append(base)
810 811

  
811
-