From 08fb79d6be44a003af357045eed92dfe5ea171c1 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Wed, 10 Oct 2018 19:08:58 +0300 Subject: [PATCH] EA-92079 - NPE: XmlUtil.getCharFromEntityRef reporting wrong entities --- .../com/intellij/codeInsight/XmlUtilTest.java | 18 ++++++++++++++++++ .../src/com/intellij/xml/util/XmlUtil.java | 7 +++---- 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 xml/tests/src/com/intellij/codeInsight/XmlUtilTest.java diff --git a/xml/tests/src/com/intellij/codeInsight/XmlUtilTest.java b/xml/tests/src/com/intellij/codeInsight/XmlUtilTest.java new file mode 100644 index 000000000000..b21a13a7bf35 --- /dev/null +++ b/xml/tests/src/com/intellij/codeInsight/XmlUtilTest.java @@ -0,0 +1,18 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.codeInsight; + +import com.intellij.xml.util.XmlUtil; +import junit.framework.TestCase; + +public class XmlUtilTest extends TestCase { + + public void testDecodeEntityRef() { + assertEquals('&', XmlUtil.getCharFromEntityRef("&")); + try { + XmlUtil.getCharFromEntityRef("&unknown;"); + fail("Exception should be thrown"); + } + catch (AssertionError ignore) { + } + } +} diff --git a/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java b/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java index ecd8eb3f3341..9ae04de768ea 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java @@ -299,6 +299,9 @@ public class XmlUtil { if (text.charAt(1) != '#') { text = text.substring(1, text.length() - 1); char c = XmlTagUtil.getCharacterByEntityName(text); + if (c == 0) { + LOG.error("Unknown entity: " + text); + } return c == 0 ? ' ' : c; } text = text.substring(2, text.length() - 1); @@ -320,10 +323,6 @@ public class XmlUtil { catch (NumberFormatException e) { return 0; } - catch (NullPointerException e) { - LOG.error("Cannot parse ref: '" + text + "'", e); - return 0; - } } public static boolean attributeFromTemplateFramework(@NonNls final String name, final XmlTag tag) {