summaryrefslogtreecommitdiff
path: root/tools/aapt2/cmd/Compile.cpp
diff options
context:
space:
mode:
authory <rtmitchell@google.com>2018-04-11 09:54:56 -0700
committery <rtmitchell@google.com>2018-04-11 15:52:43 -0700
commitd6b83299a6d636c67fee8bd4ae07555a9ae2269a (patch)
tree3ba4327af7207a6a57c2375f87cdda1804651d08 /tools/aapt2/cmd/Compile.cpp
parent65317bac02e993d1313a1958a8497ff5f2a2ecd5 (diff)
AAPT: Multiple period legacy support and errors
AAPT would accept files with multiple periods in the filename as input. This lead to cases explained in b/74999475. This change adds error messages for files with multiple periods unless the legacy flag is present. With the legacy flag present, AAPT2 will behave like AAPT rather than throwing an error. Test: Added tests to aapt2_tests Bug: 73071563 Bug: 74999475 Change-Id: I28dfceeea7b39f8e4b9e6671e0fc8793cf388f52
Diffstat (limited to 'tools/aapt2/cmd/Compile.cpp')
-rw-r--r--tools/aapt2/cmd/Compile.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index 2d83a14e541d..ab8a4b77a89d 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -100,10 +100,20 @@ static Maybe<ResourcePathData> ExtractResourcePathData(const std::string& path,
std::string& filename = parts[parts.size() - 1];
StringPiece name = filename;
StringPiece extension;
- size_t dot_pos = filename.find('.');
- if (dot_pos != std::string::npos) {
- extension = name.substr(dot_pos + 1, filename.size() - (dot_pos + 1));
- name = name.substr(0, dot_pos);
+
+ const std::string kNinePng = ".9.png";
+ if (filename.size() > kNinePng.size()
+ && std::equal(kNinePng.rbegin(), kNinePng.rend(), filename.rbegin())) {
+ // Split on .9.png if this extension is present at the end of the file path
+ name = name.substr(0, filename.size() - kNinePng.size());
+ extension = "9.png";
+ } else {
+ // Split on the last period occurrence
+ size_t dot_pos = filename.rfind('.');
+ if (dot_pos != std::string::npos) {
+ extension = name.substr(dot_pos + 1, filename.size() - (dot_pos + 1));
+ name = name.substr(0, dot_pos);
+ }
}
return ResourcePathData{Source(path), dir_str.to_string(), name.to_string(),
@@ -768,12 +778,13 @@ int Compile(const std::vector<StringPiece>& args, IDiagnostics* diagnostics) {
// We use a different extension (not necessary anymore, but avoids altering the existing
// build system logic).
path_data.extension = "arsc";
+
} else if (const ResourceType* type = ParseResourceType(path_data.resource_dir)) {
if (*type != ResourceType::kRaw) {
if (path_data.extension == "xml") {
compile_func = &CompileXml;
- } else if ((!options.no_png_crunch && path_data.extension == "png") ||
- path_data.extension == "9.png") {
+ } else if ((!options.no_png_crunch && path_data.extension == "png")
+ || path_data.extension == "9.png") {
compile_func = &CompilePng;
}
}
@@ -784,6 +795,17 @@ int Compile(const std::vector<StringPiece>& args, IDiagnostics* diagnostics) {
continue;
}
+ // Treat periods as a reserved character that should not be present in a file name
+ // Legacy support for AAPT which did not reserve periods
+ if (compile_func != &CompileFile && !options.legacy_mode
+ && std::count(path_data.name.begin(), path_data.name.end(), '.') != 0) {
+ error = true;
+ context.GetDiagnostics()->Error(DiagMessage() << "resource file '" << path_data.source.path
+ << "' name cannot contain '.' other than for"
+ << "specifying the extension");
+ continue;
+ }
+
// Compile the file.
const std::string out_path = BuildIntermediateContainerFilename(path_data);
error |= !compile_func(&context, options, path_data, archive_writer.get(), out_path);