diff --git a/changelog.md b/changelog.md index ea34d0d..2fbfd3f 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ ### Fixed - Multiple build variants are published after upgrading gradle maven publish plugin to [0.19.0](https://github.com/vanniktech/gradle-maven-publish-plugin/blob/master/CHANGELOG.md#version-0190-2022-02-26) +- A NPE in SingleApostropheDetector for atypical resource definitions ### Security diff --git a/checks/src/main/kotlin/com/faithlife/lint/SingleApostropheDetector.kt b/checks/src/main/kotlin/com/faithlife/lint/SingleApostropheDetector.kt index 3d8eaa2..6759313 100644 --- a/checks/src/main/kotlin/com/faithlife/lint/SingleApostropheDetector.kt +++ b/checks/src/main/kotlin/com/faithlife/lint/SingleApostropheDetector.kt @@ -2,6 +2,7 @@ package com.faithlife.lint import com.android.resources.ResourceFolderType import com.android.tools.lint.detector.api.* +import com.android.utils.text import org.w3c.dom.Element class SingleApostropheDetector : ResourceXmlDetector() { @@ -11,20 +12,24 @@ class SingleApostropheDetector : ResourceXmlDetector() { override fun getApplicableElements(): MutableCollection = mutableListOf("string") override fun visitElement(context: XmlContext, element: Element) { - if (SINGLE_APOSTROPHE_REGEX.containsMatchIn(element.firstChild.nodeValue)) { - val fix = LintFix.create() - .replace() - .pattern("\\\\?'") - .with("’") - .build() - - context.report( - ISSUE, - element, - context.getLocation(element), - "Prefer unicode apostrophes.\n\nhttps://wiki.lrscorp.net/Use_Unicode_Punctuation_Characters", - fix - ) + try { + if (SINGLE_APOSTROPHE_REGEX.containsMatchIn(element.textContent)) { + val fix = LintFix.create() + .replace() + .pattern("\\\\?'") + .with("’") + .build() + + context.report( + ISSUE, + element, + context.getLocation(element), + "Prefer unicode apostrophes.\n\nhttps://wiki.lrscorp.net/Use_Unicode_Punctuation_Characters", + fix + ) + } + } catch (e: NullPointerException) { + println("File: ${context.file.absolutePath}\nText: ${element.text()} Element: $element") } } diff --git a/gradle.properties b/gradle.properties index 9410c15..261f020 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.jvmargs=-Xmx3g -XX:+UseParallelGC GROUP=com.faithlife -VERSION_NAME=1.1.5 +VERSION_NAME=1.1.6 POM_URL=https://github.com/Faithlife/AndroidLint/ POM_ARTIFACT_ID=android-lint