Merge pull request #1176 from tdesveauxPKFX/host/fix_normalize
path.normalize: Fix when call with path surrounded with quotes
This commit is contained in:
commit
ea1df508bc
@ -9,6 +9,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#define IS_SEP(__c) ((__c) == '/' || (__c) == '\\')
|
||||
#define IS_QUOTE(__c) ((__c) == '\"' || (__c) == '\'')
|
||||
|
||||
#define IS_UPPER_ALPHA(__c) ((__c) >= 'A' && (__c) <= 'Z')
|
||||
#define IS_LOWER_ALPHA(__c) ((__c) >= 'a' && (__c) <= 'z')
|
||||
@ -16,8 +17,8 @@
|
||||
|
||||
#define IS_SPACE(__c) ((__c >= '\t' && __c <= '\r') || __c == ' ')
|
||||
|
||||
static void* normalize_substring(const char* srcPtr, const char* srcEnd, char* dstPtr) {
|
||||
|
||||
static void* normalize_substring(const char* srcPtr, const char* srcEnd, char* dstPtr)
|
||||
{
|
||||
#define IS_END(__p) (__p >= srcEnd || *__p == '\0')
|
||||
#define IS_SEP_OR_END(__p) (IS_END(__p) || IS_SEP(*__p))
|
||||
|
||||
@ -114,6 +115,14 @@ int path_normalize(lua_State* L)
|
||||
while (*endPtr && !IS_SPACE(*endPtr))
|
||||
++endPtr;
|
||||
|
||||
// path is surrounded with quotes
|
||||
if (readPtr != endPtr &&
|
||||
IS_QUOTE(*readPtr) && IS_QUOTE(endPtr[-1]) &&
|
||||
*readPtr == endPtr[-1])
|
||||
{
|
||||
*(writePtr++) = *(readPtr++);
|
||||
}
|
||||
|
||||
writePtr = normalize_substring(readPtr, endPtr, writePtr);
|
||||
|
||||
// skip any white spaces between sub paths
|
||||
|
@ -719,3 +719,8 @@
|
||||
test.isequal("//myawesomeserver/test", path.normalize("//myawesomeserver/test/"))
|
||||
test.isequal("//myawesomeserver/test", path.normalize("///myawesomeserver/test/"))
|
||||
end
|
||||
|
||||
function suite.normalize_quotedpath()
|
||||
test.isequal("\"../../test/test/\"", path.normalize("\"../../test/test/\""))
|
||||
test.isequal("\"../../test/\"", path.normalize("\"../../test/../test/\""))
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user