From ec60b9ad83431f70cde34b80d1556b9523a0d99c Mon Sep 17 00:00:00 2001
From: Trim21 <trim21me@gmail.com>
Date: Sun, 5 Jan 2020 15:59:20 +0800
Subject: [PATCH] fix(poetry): version string with single quote (#5090)

fixes #5015
---
 lib/manager/poetry/update.ts                        | 13 +++++++++----
 .../poetry/__snapshots__/update.spec.ts.snap        |  8 +++++---
 test/manager/poetry/_fixtures/pyproject.2.toml      |  4 ++--
 test/manager/poetry/_fixtures/pyproject.7.toml      |  2 +-
 test/manager/poetry/_fixtures/pyproject.8.toml      |  2 +-
 5 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/lib/manager/poetry/update.ts b/lib/manager/poetry/update.ts
index eb2598764c..9d2c9d135d 100644
--- a/lib/manager/poetry/update.ts
+++ b/lib/manager/poetry/update.ts
@@ -7,7 +7,10 @@ import { PoetryFile } from './types';
 // TODO: Maybe factor out common code from pipenv.updateDependency and poetry.updateDependency
 // Return true if the match string is found at index in content
 function matchAt(content: string, index: number, match: string): boolean {
-  return content.substring(index, index + match.length) === match;
+  return (
+    content.substring(index, index + match.length + 2) === `"${match}"` ||
+    content.substring(index, index + match.length + 2) === `'${match}'`
+  );
 }
 
 // Replace oldString with newString at location index of content
@@ -17,11 +20,13 @@ function replaceAt(
   oldString: string,
   newString: string
 ): string {
-  logger.debug(`Replacing ${oldString} with ${newString} at index ${index}`);
+  logger.debug(
+    `Replacing \`${oldString}\` with ${newString} at index ${index}`
+  );
   return (
     content.substr(0, index) +
     newString +
-    content.substr(index + oldString.length)
+    content.substr(index + oldString.length + 2)
   );
 }
 
@@ -73,7 +78,7 @@ export function updateDependency(
   } else {
     parsedContents.tool.poetry[depType][depName] = newValue;
   }
-  const searchString = `"${oldVersion}"`;
+  const searchString = `${oldVersion}`;
   const newString = `"${newValue}"`;
   let newFileContent = null;
   let searchIndex = fileContent.indexOf(`[${depType}]`) + depType.length;
diff --git a/test/manager/poetry/__snapshots__/update.spec.ts.snap b/test/manager/poetry/__snapshots__/update.spec.ts.snap
index fc43034e3f..f4ac4233ec 100644
--- a/test/manager/poetry/__snapshots__/update.spec.ts.snap
+++ b/test/manager/poetry/__snapshots__/update.spec.ts.snap
@@ -33,13 +33,14 @@ authors = [\\"John Doe <john.doe@gmail.com>\\"]
 [tool.poetry.dependencies]
 dep1 = { version =  \\"1.0.0\\" }
 dep2 = { version = \\"^0.6.0\\" }
-dep3 = { path = \\"/some/path/\\", version = \\"^0.33.6\\" }
+dep3 = { path = \\"/some/path/\\", version = '^0.33.6' }
 dep4 = { path = \\"/some/path/\\" }
 
 [tool.poetry.extras]
 extra_dep1 = \\"^0.8.3\\"
 extra_dep2 = \\"^0.9.4\\"
-extra_dep3 = \\"^0.4.0\\""
+extra_dep3 = '^0.4.0'
+"
 `;
 
 exports[`manager/poetry/update updateDependency replaces nested value for path dependency 1`] = `
@@ -58,7 +59,8 @@ dep4 = { path = \\"/some/path/\\" }
 [tool.poetry.extras]
 extra_dep1 = \\"^0.8.3\\"
 extra_dep2 = \\"^0.9.4\\"
-extra_dep3 = \\"^0.4.0\\""
+extra_dep3 = '^0.4.0'
+"
 `;
 
 exports[`manager/poetry/update updateDependency upgrades dev-dependencies 1`] = `
diff --git a/test/manager/poetry/_fixtures/pyproject.2.toml b/test/manager/poetry/_fixtures/pyproject.2.toml
index c12a5a77c1..906c83920b 100644
--- a/test/manager/poetry/_fixtures/pyproject.2.toml
+++ b/test/manager/poetry/_fixtures/pyproject.2.toml
@@ -7,10 +7,10 @@ authors = ["John Doe <john.doe@gmail.com>"]
 [tool.poetry.dependencies]
 dep1 = { version =  "*" }
 dep2 = { version = "^0.6.0" }
-dep3 = { path = "/some/path/", version = "^0.33.6" }
+dep3 = { path = "/some/path/", version = '^0.33.6' }
 dep4 = { path = "/some/path/" }
 
 [tool.poetry.extras]
 extra_dep1 = "^0.8.3"
 extra_dep2 = "^0.9.4"
-extra_dep3 = "^0.4.0"
\ No newline at end of file
+extra_dep3 = '^0.4.0'
diff --git a/test/manager/poetry/_fixtures/pyproject.7.toml b/test/manager/poetry/_fixtures/pyproject.7.toml
index 398e371b58..c4aedc4362 100644
--- a/test/manager/poetry/_fixtures/pyproject.7.toml
+++ b/test/manager/poetry/_fixtures/pyproject.7.toml
@@ -6,4 +6,4 @@ authors = ["John Doe <john.doe@gmail.com>"]
 source = []
 
 [tool.poetry.dependencies]
-dep0 = "0.0.0"
\ No newline at end of file
+dep0 = '0.0.0'
diff --git a/test/manager/poetry/_fixtures/pyproject.8.toml b/test/manager/poetry/_fixtures/pyproject.8.toml
index f15169159e..35f8fd227d 100644
--- a/test/manager/poetry/_fixtures/pyproject.8.toml
+++ b/test/manager/poetry/_fixtures/pyproject.8.toml
@@ -5,7 +5,7 @@ description = ""
 authors = ["John Doe <john.doe@gmail.com>"]
 
 [tool.poetry.dependencies]
-dep0 = "0.0.0"
+dep0 = '0.0.0'
 
 [[tool.poetry.source]]
 name = "foo"
-- 
GitLab