Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit33be9d3

Browse files
committed
Removes duplicate slashes from the path in canonicalize_path(). It
preserve double leading slashes on Win32.e.g. ////a////b => /a/b
1 parent336969e commit33be9d3

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

‎src/port/path.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/port/path.c,v 1.44 2004/11/06 21:39:45 tgl Exp $
11+
* $PostgreSQL: pgsql/src/port/path.c,v 1.45 2004/11/07 02:12:17 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -203,21 +203,22 @@ join_path_components(char *ret_path,
203203
*o make Win32 path use Unix slashes
204204
*o remove trailing quote on Win32
205205
*o remove trailing slash
206+
*o remove duplicate adjacent separators
206207
*o remove trailing '.'
207208
*o process trailing '..' ourselves
208209
*/
209210
void
210211
canonicalize_path(char*path)
211212
{
212-
#ifdefWIN32
213+
char*p,*to_p;
214+
boolwas_sep= false;
213215

216+
#ifdefWIN32
214217
/*
215218
* The Windows command processor will accept suitably quoted paths
216219
* with forward slashes, but barfs badly with mixed forward and back
217220
* slashes.
218221
*/
219-
char*p;
220-
221222
for (p=path;*p;p++)
222223
{
223224
if (*p=='\\')
@@ -226,7 +227,7 @@ canonicalize_path(char *path)
226227

227228
/*
228229
* In Win32, if you do: prog.exe "a b" "\c\d\" the system will pass
229-
* \c\d" as argv[2].
230+
* \c\d" as argv[2], so trim off trailing quote.
230231
*/
231232
if (p>path&&*(p-1)=='"')
232233
*(p-1)='/';
@@ -239,6 +240,27 @@ canonicalize_path(char *path)
239240
*/
240241
trim_trailing_separator(path);
241242

243+
/*
244+
*Remove duplicate adjacent separators
245+
*/
246+
p=path;
247+
#ifdefWIN32
248+
/* Don't remove leading double-slash on Win32 */
249+
if (*p)
250+
p++;
251+
#endif
252+
to_p=p;
253+
for (;*p;p++,to_p++)
254+
{
255+
/* Handle many adjacent slashes, like "/a///b" */
256+
while (*p=='/'&&was_sep)
257+
p++;
258+
if (to_p!=p)
259+
*to_p=*p;
260+
was_sep= (*p=='/');
261+
}
262+
*to_p='\0';
263+
242264
/*
243265
* Remove any trailing uses of "." and process ".." ourselves
244266
*/
@@ -247,9 +269,7 @@ canonicalize_path(char *path)
247269
intlen=strlen(path);
248270

249271
if (len>2&&strcmp(path+len-2,"/.")==0)
250-
{
251272
trim_directory(path);
252-
}
253273
elseif (len>3&&strcmp(path+len-3,"/..")==0)
254274
{
255275
trim_directory(path);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp