aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/importer.cc
diff options
context:
space:
mode:
authorGravatar temporal <temporal@630680e5-0e50-0410-840e-4b1c322b438d>2008-07-16 20:57:56 +0000
committerGravatar temporal <temporal@630680e5-0e50-0410-840e-4b1c322b438d>2008-07-16 20:57:56 +0000
commite773b4325382319cf0f97808c1153b4b6673605a (patch)
treec9d474995c01395fcd00d2a08b51ae3ca063994d /src/google/protobuf/compiler/importer.cc
parent928ebb6b55a23972573328e0ca9500d9730249af (diff)
Allow trailing slashes in --proto_path mappings.
Patch by Kevin Ko <kevin.s.ko@gmail.com>.
Diffstat (limited to 'src/google/protobuf/compiler/importer.cc')
-rw-r--r--src/google/protobuf/compiler/importer.cc10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc
index 61182933..62089cdc 100644
--- a/src/google/protobuf/compiler/importer.cc
+++ b/src/google/protobuf/compiler/importer.cc
@@ -280,10 +280,18 @@ static bool ApplyMapping(const string& filename,
// Not an exact match. Is the next character a '/'? Otherwise,
// this isn't actually a match at all. E.g. the prefix "foo/bar"
// does not match the filename "foo/barbaz".
+ int after_prefix_start = -1;
if (filename[old_prefix.size()] == '/') {
+ after_prefix_start = old_prefix.size() + 1;
+ } else if (filename[old_prefix.size() - 1] == '/') {
+ // old_prefix is never empty, and canonicalized paths never have
+ // consecutive '/' characters.
+ after_prefix_start = old_prefix.size();
+ }
+ if (after_prefix_start != -1) {
// Yep. So the prefixes are directories and the filename is a file
// inside them.
- string after_prefix = filename.substr(old_prefix.size() + 1);
+ string after_prefix = filename.substr(after_prefix_start);
if (ContainsParentReference(after_prefix)) {
// We do not allow the file name to use "..".
return false;