From 5ce8317445fb96aee2a98f7384fbcf70e8be99d9 Mon Sep 17 00:00:00 2001 From: Kaiwen Xu Date: Wed, 12 Nov 2014 22:20:20 -0500 Subject: [PATCH] Add support for stream wrapper in include_path. set_include_path now supports parsing of stream wrapper path (e.g. proto://path). Passing vfsstream knownFileCanBeResolved test. --- hphp/runtime/base/builtin-functions.cpp | 11 +++++-- hphp/runtime/base/request-injection-data.cpp | 32 ++++++++++++++++--- hphp/test/frameworks/results/vfsstream.expect | 2 +- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/hphp/runtime/base/builtin-functions.cpp b/hphp/runtime/base/builtin-functions.cpp index 2ffd026edaefd..585f5ba8221ca 100644 --- a/hphp/runtime/base/builtin-functions.cpp +++ b/hphp/runtime/base/builtin-functions.cpp @@ -818,8 +818,9 @@ String resolve_include(const String& file, const char* currentDir, for (int i = 0; i < (int)path_count; i++) { String path(""); String includePath(includePaths[i]); + bool is_stream_wrapper = (includePath.find("://") > 0); - if (includePath[0] != '/') { + if (!is_stream_wrapper && includePath[0] != '/') { path += (g_context->getCwd() + "/"); } @@ -830,7 +831,13 @@ String resolve_include(const String& file, const char* currentDir, } path += file; - String can_path = FileUtil::canonicalize(path); + + String can_path; + if (!is_stream_wrapper) { + can_path = FileUtil::canonicalize(path); + } else { + can_path = String(path.c_str()); + } if (tryFile(can_path, ctx)) { return can_path; diff --git a/hphp/runtime/base/request-injection-data.cpp b/hphp/runtime/base/request-injection-data.cpp index 50cba232912be..0d3234304271c 100644 --- a/hphp/runtime/base/request-injection-data.cpp +++ b/hphp/runtime/base/request-injection-data.cpp @@ -102,11 +102,35 @@ void RequestInjectionData::threadInit() { "include_path", getDefaultIncludePath().c_str(), IniSetting::SetAndGet( [this](const std::string& value) { - auto paths = HHVM_FN(explode)(":", value); m_include_paths.clear(); - for (ArrayIter iter(paths); iter; ++iter) { - m_include_paths.push_back( - iter.second().toString().toCppString()); + int pos = value.find(':'); + if (pos < 0) { + m_include_paths.push_back(value); + } else { + int pos0 = 0; + do { + // Check for stream wrapper + if (value.length() > pos + 2 && + value[pos + 1] == '/' && + value[pos + 2] == '/') { + // .:// or ..:// is not stream wrapper + if (((pos - pos0) >= 1 && value[pos - 1] != '.') || + ((pos - pos0) >= 2 && value[pos - 2] != '.') || + (pos - pos0) > 2) { + pos += 3; + continue; + } + } + m_include_paths.push_back( + value.substr(pos0, pos - pos0)); + pos++; + pos0 = pos; + } while ((pos = value.find(':', pos)) >= 0); + + if (pos0 <= value.length()) { + m_include_paths.push_back( + value.substr(pos0)); + } } return true; }, diff --git a/hphp/test/frameworks/results/vfsstream.expect b/hphp/test/frameworks/results/vfsstream.expect index d892341ceefd6..6bd3debef334d 100644 --- a/hphp/test/frameworks/results/vfsstream.expect +++ b/hphp/test/frameworks/results/vfsstream.expect @@ -259,7 +259,7 @@ org\bovigo\vfs\vfsStreamFileTestCase::writeEmptyFile org\bovigo\vfs\vfsStreamGlobTestCase::globDoesNotWorkWithVfsStreamUrls . org\bovigo\vfs\vfsStreamResolveIncludePathTestCase::knownFileCanBeResolved -F +. org\bovigo\vfs\vfsStreamResolveIncludePathTestCase::unknownFileCanNotBeResolvedYieldsFalse . org\bovigo\vfs\vfsStreamTestCase::copyFromEmptyFolder