From f64591cf3652b644213c65e3acce26bc67bc0993 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Fri, 18 May 2018 08:06:00 +0200 Subject: Warn if prompt contains leading or trailing whitespace Also strip the prompt in that case. Leading/trailing whitespace in prompts leads to ugly workarounds in e.g. reStructuredText documentation, where '*prompt *' is invalid. --- kconfiglib.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index b673c10..5913adc 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -2251,7 +2251,16 @@ class Kconfig(object): self._warn("{} defined with multiple prompts in single location" .format(_name_and_loc(node.item))) - node.prompt = (self._expect_str(), self._parse_cond()) + prompt = self._expect_str() + if prompt != prompt.strip(): + self._warn("{} has leading or trailing whitespace in its prompt" + .format(_name_and_loc(node.item))) + + # This avoid issues for e.g. reStructuredText documentation, where + # '*prompt *' is invalid + prompt = prompt.strip() + + node.prompt = (prompt, self._parse_cond()) def _parse_help(self, node): # Find first non-blank (not all-space) line and get its indentation -- cgit v1.2.3