Repository: devopshq/artifactory

Issue:
/ operator on ArtifactoryPath fails if string contains "/"
Maybe linked to #31.

```python
>>> arti = Artifactory("http://my.artifactory.ext/artifactory")
>>> arti
ArtifactoryPath('http://my.artifactory.ext/artifactory')
>>> arti / "foo"
ArtifactoryPath('http://my.artifactory.ext/artifactory/foo')
>>> arti / "foo" / "bar"
ArtifactoryPath('http://my.artifactory.ext/artifactory/foo/bar')
>>> arti / "foo/bar"
ArtifactoryPath('foo/bar/')  # expected: http://my.artifactory.ext/artifactory/foo/bar
```

Discussion:

Patch:
diff --git a/artifactory.py b/artifactory.py
index 3b14d4f..079b7c4 100755
--- a/artifactory.py
+++ b/artifactory.py
@@ -358,11 +358,16 @@ class _ArtifactoryFlavour(pathlib._Flavour):
             parts = part.split(mark)
         else:
             url = urllib3.util.parse_url(part)
+
+            if (without_http_prefix(part).strip("/") == part.strip("/") and
+                    url.path and not url.path.strip("/").startswith("artifactory")):
+                return '', '', part
+
             if url.path is None or url.path == sep:
                 if url.scheme:
                     return part.rstrip(sep), '', ''
                 return '', '', part
-            elif 'artifactory' in url.path:
+            elif url.path.lstrip("/").startswith("artifactory"):
                 mark = sep + 'artifactory' + sep
                 parts = part.split(mark)
             else:


Test patch:
diff --git a/tests/unit/test_artifactory_path.py b/tests/unit/test_artifactory_path.py
index 0460d7f..8fd13d9 100644
--- a/tests/unit/test_artifactory_path.py
+++ b/tests/unit/test_artifactory_path.py
@@ -88,6 +88,9 @@ class ArtifactoryFlavorTest(unittest.TestCase):
               ('http://artifactory.local/artifactory', '/foo/', 'bar'))
         check("https://artifactory.a.b.c.d/artifactory/foo/bar",
               ('https://artifactory.a.b.c.d/artifactory', '/foo/', 'bar'))
+        check("https://artifactory.a.b.c.d/artifactory/foo/artifactory/bar",
+              ('https://artifactory.a.b.c.d/artifactory', '/foo/',
+               'artifactory/bar'))
 
     def test_splitroot_custom_drv(self):
         """
@@ -119,6 +122,8 @@ class ArtifactoryFlavorTest(unittest.TestCase):
               ('https://artifacts.example.com', '/root/', 'parts'))
         check("https://artifacts.example.com/root/parts/",
               ('https://artifacts.example.com', '/root/', 'parts'))
+        check("https://artifacts.example.com/root/artifactory/parts/",
+              ('https://artifacts.example.com', '/root/', 'artifactory/parts'))
 
     def test_splitroot_custom_root(self):
         check = self._check_splitroot
@@ -137,6 +142,8 @@ class ArtifactoryFlavorTest(unittest.TestCase):
               ('http://custom/root', '/foo/', 'bar'))
         check("https://custom/root/foo/baz",
               ('https://custom/root', '/foo/', 'baz'))
+        check("https://custom/root/foo/with/artifactory/folder/baz",
+              ('https://custom/root', '/foo/', 'with/artifactory/folder/baz'))
 
     def test_parse_parts(self):
         check = self._check_parse_parts
@@ -160,6 +167,11 @@ class ArtifactoryFlavorTest(unittest.TestCase):
               ('http://example.com/artifactory', '/foo/',
                ['http://example.com/artifactory/foo/', 'bar', 'artifactory']))
 
+        check(['http://example.com/artifactory/foo/bar/artifactory/fi'],
+              ('http://example.com/artifactory', '/foo/',
+               ['http://example.com/artifactory/foo/', 'bar', 'artifactory',
+                'fi']))
+
 
 class PureArtifactoryPathTest(unittest.TestCase):
     cls = artifactory.PureArtifactoryPath
@@ -225,6 +237,23 @@ class PureArtifactoryPathTest(unittest.TestCase):
         c = b / "path.txt"
         self.assertEqual(str(c), "http://b/artifactory/reponame/f/path.txt")
 
+    def test_join_with_artifactory_folder(self):
+        P = self.cls
+
+        b = P("http://b/artifactory/reponame/path/with/artifactory/folder")
+        c = b / "path.txt"
+        self.assertEqual(str(c), "http://b/artifactory/reponame/path/with/artifactory/folder/path.txt")
+
+    def test_join_with_multiple_folder_and_artifactory_substr_in_it(self):
+        """
+        https://github.com/devopshq/artifactory/issues/58
+        """
+        P = self.cls
+
+        b = P("http://b/artifactory/reponame")
+        c = b / "path/with/multiple/subdir/and/artifactory/path.txt"
+        self.assertEqual(str(c), "http://b/artifactory/reponame/path/with/multiple/subdir/and/artifactory/path.txt")
+
 
 class ArtifactoryAccessorTest(unittest.TestCase):
     """ Test the real artifactory integration """