From d1bb5df72d88a4f35a552c90bd7f3893324ceab4 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 16 Jul 2003 11:00:36 +0000 Subject: [PATCH] PathTokenizer didn't deal correctly with ../ style relative paths following a colon in Unix style PATH structures on Netware. Submitted by: Jeff Tulley git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274829 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/PathTokenizer.java | 6 +++-- .../org/apache/tools/ant/types/PathTest.java | 25 ++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/org/apache/tools/ant/PathTokenizer.java b/src/main/org/apache/tools/ant/PathTokenizer.java index 9727b63a3..ef3927c9b 100644 --- a/src/main/org/apache/tools/ant/PathTokenizer.java +++ b/src/main/org/apache/tools/ant/PathTokenizer.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000,2002 The Apache Software Foundation. All rights + * Copyright (c) 2000,2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -176,7 +176,9 @@ public class PathTokenizer { // make sure we aren't going to get the path separator next if (!nextToken.equals(File.pathSeparator)) { if (nextToken.equals(":")) { - if (!token.startsWith("/") && !token.startsWith("\\")) { + if (!token.startsWith("/") && !token.startsWith("\\") + && !token.startsWith(".") + && !token.startsWith("..")) { // it indeed is a drive spec, get the next bit String oneMore = tokenizer.nextToken().trim(); if (!oneMore.equals(File.pathSeparator)) { diff --git a/src/testcases/org/apache/tools/ant/types/PathTest.java b/src/testcases/org/apache/tools/ant/types/PathTest.java index d00b8d9b1..6d1c8a607 100644 --- a/src/testcases/org/apache/tools/ant/types/PathTest.java +++ b/src/testcases/org/apache/tools/ant/types/PathTest.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -104,6 +104,29 @@ public class PathTest extends TestCase { } } + public void testRelativePathUnixStyle() { + project.setBasedir("src/etc"); + Path p = new Path(project, "..:testcases"); + String[] l = p.list(); + assertEquals("two items, Unix style", 2, l.length); + if (isUnixStyle) { + assertTrue("test resolved relative to src/etc", + l[0].endsWith("/src")); + assertTrue("test resolved relative to src/etc", + l[1].endsWith("/src/etc/testcases")); + } else if (isNetWare) { + assertTrue("test resolved relative to src/etc", + l[0].endsWith("\\src")); + assertTrue("test resolved relative to src/etc", + l[1].endsWith("\\src\\etc\\testcases")); + } else { + assertTrue("test resolved relative to src/etc", + l[0].endsWith("\\src")); + assertTrue("test resolved relative to src/etc", + l[1].endsWith("\\src\\etc\\testcases")); + } + } + public void testConstructorWindowsStyle() { Path p = new Path(project, "\\a;\\b"); String[] l = p.list();