From 24a1254f034a238f481f8b889a961dbde99c551d Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Fri, 30 Sep 2016 15:29:14 +0200 Subject: [PATCH 1/4] Explicitly disallow duplications of URL and save_as. --- pelican/readers.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pelican/readers.py b/pelican/readers.py index 415e7558..56e54355 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -31,6 +31,20 @@ except ImportError: # This means that _filter_discardable_metadata() must be called on processed # metadata dicts before use, to remove the items with the special value. _DISCARD = object() + +DUPLICATES_DEFINITIONS_ALLOWED = { + 'tags': False, + 'date': False, + 'modified': False, + 'status': False, + 'category': False, + 'author': False, + 'save_as': False, + 'URL': False, + 'authors': False, + 'slug': False +} + METADATA_PROCESSORS = { 'tags': lambda x, y: ([ Tag(tag, y) @@ -264,7 +278,7 @@ class MarkdownReader(BaseReader): self._md.reset() formatted = self._md.convert(formatted_values) output[name] = self.process_metadata(name, formatted) - elif name in METADATA_PROCESSORS: + elif not DUPLICATES_DEFINITIONS_ALLOWED.get(name, True): if len(value) > 1: logger.warning( 'Duplicate definition of `%s` ' From 9e574e9d8c6e4d6377a6fcefe1579bb998c7223a Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Fri, 30 Sep 2016 15:33:05 +0200 Subject: [PATCH 2/4] Just in case someone forgot the DUPLICATES_DEFINITIONS_ALLOWED but add in METADATA_PROCESSORS. --- pelican/readers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pelican/readers.py b/pelican/readers.py index 56e54355..5220f1a0 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -278,7 +278,8 @@ class MarkdownReader(BaseReader): self._md.reset() formatted = self._md.convert(formatted_values) output[name] = self.process_metadata(name, formatted) - elif not DUPLICATES_DEFINITIONS_ALLOWED.get(name, True): + elif (not DUPLICATES_DEFINITIONS_ALLOWED.get(name, True) or + name in METADATA_PROCESSORS): if len(value) > 1: logger.warning( 'Duplicate definition of `%s` ' From e8a87e5d3cb82081127a8a07da574059668688de Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Mon, 10 Oct 2016 12:23:26 +0200 Subject: [PATCH 3/4] As not allowing duplicates in processed items is counter intuitive, let's allow it. Also it may be allowed in the future (to process multiple values). Also @avaris think it's bad to test something twice (see https://github.com/getpelican/pelican/pull/2017), but for me confusion lies in the "Why is list processing forbidden?", so, in a way, our ideas converges in "let's not disallow processed items to be lists". This reverts commit 9e574e9d8c6e4d6377a6fcefe1579bb998c7223a. --- pelican/readers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pelican/readers.py b/pelican/readers.py index 503db679..a7712f0b 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -278,8 +278,7 @@ class MarkdownReader(BaseReader): self._md.reset() formatted = self._md.convert(formatted_values) output[name] = self.process_metadata(name, formatted) - elif (not DUPLICATES_DEFINITIONS_ALLOWED.get(name, True) or - name in METADATA_PROCESSORS): + elif not DUPLICATES_DEFINITIONS_ALLOWED.get(name, True): if len(value) > 1: logger.warning( 'Duplicate definition of `%s` ' From e07c53a09dab16ec33e44a84a1c5db5e58deb61c Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Wed, 26 Oct 2016 08:34:52 +0200 Subject: [PATCH 4/4] FIX: Those keys are looked up lowercased. --- pelican/readers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/readers.py b/pelican/readers.py index a7712f0b..74b617e6 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -40,7 +40,7 @@ DUPLICATES_DEFINITIONS_ALLOWED = { 'category': False, 'author': False, 'save_as': False, - 'URL': False, + 'url': False, 'authors': False, 'slug': False }