Incorrect property escapes

Incorrect property escapes

This is an error.

Id

PropertyEscape

Summary

Incorrect property escapes

Severity

Error

Category

Correctness

Platform

Any

Vendor

Android Open Source Project

Feedback

https://issuetracker.google.com/issues/new?component=192708

Since

Initial

Affects

Property files

Editing

This check runs on the fly in the IDE editor

Implementation

Source Code

Tests

Source Code

Copyright Year

2014

All backslashes and colons in .property files must be escaped with a backslash (\). This means that when writing a Windows path, you must escape the file separators, so the path \My\Files should be written as key=\\My\\Files.

This lint check has an associated quickfix available in the IDE.

Example

Here is an example of lint warnings produced by this check:

local.properties:11:Error: Windows file separators (\) and drive letter
separators (':') must be escaped (\\) in property files; use
C\:\\my\\path\\to\\sdk [PropertyEscape]
windows.dir=C:\my\path\to\sdk
             --------------
local.properties:14:Error: Windows file separators (\) and drive letter
separators (':') must be escaped (\\) in property files; use
C\:\\Documents and Settings\\UserName\\Local Settings\\Application
Data\\Android\\android-studio\\sdk [PropertyEscape]
ok.sdk.dir=C:\\Documents and Settings\\UserName\\Local Settings\\Application Data\\Android\\android-studio\\sdk
            -

Here is the source file referenced above:

local.properties:

## This file is automatically generated by Android Studio. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file should *NOT* be checked into Version Control Systems, # as it contains information specific to your local configuration. # # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. sdk.dir=/Users/test/dev/sdks windows.dir=C:\my\path\to\sdk windows2.dir=C\:\\my\\path\\to\\sdk not.a.path.prop=Hello \my\path\to\sdk ok.sdk.dir=C:\\Documents and Settings\\UserName\\Local Settings\\Application Data\\Android\\android-studio\\sdk

You can also visit the source code for the unit tests for this check to see additional scenarios.

The above example was automatically extracted from the first unit test found for this lint check, PropertyFileDetector.testBasic. To report a problem with this extracted sample, visit https://issuetracker.google.com/issues/new?component=192708.

Suppressing

You can suppress false positives using one of the following mechanisms:

formatted by Markdeep 1.18