|
24 | 24 | from licensedcode._vendor import attr |
25 | 25 | from license_expression import ExpressionError |
26 | 26 | from license_expression import Licensing |
27 | | -from saneyaml import load as yaml_load |
28 | | -from saneyaml import dump as yaml_dump |
| 27 | +from saneyaml import load as saneyaml_load |
| 28 | +from saneyaml import dump as saneyaml_dump |
| 29 | +from yaml import load as yaml_load |
| 30 | +from yaml import dump as yaml_dump |
| 31 | +from yaml import CSafeLoader |
29 | 32 |
|
30 | 33 | from commoncode.fileutils import file_base_name |
31 | 34 | from commoncode.fileutils import file_name |
@@ -664,9 +667,17 @@ def validate(licenses, verbose=False, no_dupe_urls=False): |
664 | 667 |
|
665 | 668 | data = {"text": text} |
666 | 669 | # We are testing whether we can dump as yaml and load from yaml |
667 | | - # without failing (i.e. whether the text is yaml safe) |
668 | | - yaml_string = yaml_dump(data, indent=4) |
669 | | - loaded_yaml = yaml_load(yaml_string) |
| 670 | + # without failing (i.e. whether the text is yaml safe) |
| 671 | + # Using saneyaml |
| 672 | + try: |
| 673 | + yaml_string = saneyaml_dump(data, indent=4) |
| 674 | + loaded_yaml = saneyaml_load(yaml_string) |
| 675 | + except Exception: |
| 676 | + errors['GLOBAL'].append( |
| 677 | + f'Error invalid YAML text at: {lic.key}, failed during saneyaml.load()' |
| 678 | + ) |
| 679 | + # This fails because of missing line break at text end, added by saneyaml_dump |
| 680 | + # assert text == loaded_yaml["text"] |
670 | 681 |
|
671 | 682 | license_itokens = tuple(index_tokenizer(text)) |
672 | 683 | if not license_itokens: |
@@ -750,9 +761,9 @@ def validate(licenses, verbose=False, no_dupe_urls=False): |
750 | 761 | def get_yaml_safe_text(text): |
751 | 762 |
|
752 | 763 | data = {"text": text} |
753 | | - yaml_string = yaml_dump(data, indent=4) |
| 764 | + yaml_string = saneyaml_dump(data, indent=4) |
754 | 765 | try: |
755 | | - loaded_yaml = yaml_load(yaml_string) |
| 766 | + loaded_yaml = saneyaml_load(yaml_string) |
756 | 767 | except Exception: |
757 | 768 | text = text.replace('\n\n', '\n \n') |
758 | 769 | return text |
@@ -1811,6 +1822,16 @@ def validate(self, licensing=None): |
1811 | 1822 | if len(set(self.referenced_filenames)) != len(self.referenced_filenames): |
1812 | 1823 | yield 'referenced_filenames cannot contain duplicates.' |
1813 | 1824 |
|
| 1825 | + text = self.text |
| 1826 | + data = {"text": text} |
| 1827 | + # We are testing whether we can dump as yaml and load from yaml |
| 1828 | + # without failing (i.e. whether the text is yaml safe) |
| 1829 | + try: |
| 1830 | + yaml_string = saneyaml_dump(data, indent=4) |
| 1831 | + loaded_yaml = saneyaml_load(yaml_string) |
| 1832 | + except Exception: |
| 1833 | + yield (f'Error invalid YAML text at: {self.identifier}, failed during saneyaml.load()') |
| 1834 | + |
1814 | 1835 | def license_keys(self, unique=True): |
1815 | 1836 | """ |
1816 | 1837 | Return a list of license keys for this rule. |
|
0 commit comments