From 625b21ea52f6ba3029c6d30ceddef3170fdb655d Mon Sep 17 00:00:00 2001 From: Andreas Nordin Date: Mon, 29 Jun 2020 14:13:21 +0200 Subject: [PATCH] Fix faulty conversion of non-(mm2,AWG) units The parsing allows arbitrary units to be used for cable dimensions -- this might be valid units, e.g. square inches, or invalid, e.g. bananas. We only allow conversion between mm2 and AWG, so check that the gauge_unit is either of those before conversion. If not, pass through as is. --- src/wireviz/Harness.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 4ccd42ff..c50384e1 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -114,13 +114,15 @@ def create_graph(self): for _, cable in self.cables.items(): + awg_fmt = '' if cable.show_equiv: + # Only convert units we actually know about, i.e. currently + # mm2 and awg --- other units _are_ technically allowed, + # and passed through as-is. if cable.gauge_unit =='mm\u00B2': awg_fmt = f' ({awg_equiv(cable.gauge)} AWG)' - else: + elif cable.gauge_unit.upper() == 'AWG': awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)' - else: - awg_fmt = '' attributes = [f'{len(cable.colors)}x' if cable.show_wirecount else '', f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else '',