Skip to content

Commit

Permalink
Fix an NPE in SingleApostropheDetector
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Brooks committed Mar 11, 2022
1 parent 719cf52 commit 9efa47c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -11,20 +12,24 @@ class SingleApostropheDetector : ResourceXmlDetector() {
override fun getApplicableElements(): MutableCollection<String> = 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")
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 9efa47c

Please sign in to comment.