From 780ed58e3bba35fcd9e7671a79023cb65fc951d1 Mon Sep 17 00:00:00 2001 From: Nick Evans Date: Wed, 3 Apr 2019 11:17:54 -0500 Subject: [PATCH 1/2] Snippet path should not be split on space --- packages/@vuepress/markdown/lib/snippet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vuepress/markdown/lib/snippet.js b/packages/@vuepress/markdown/lib/snippet.js index b0b88f18f2..7713da90cb 100644 --- a/packages/@vuepress/markdown/lib/snippet.js +++ b/packages/@vuepress/markdown/lib/snippet.js @@ -44,7 +44,7 @@ module.exports = function snippet (md, options = {}) { const start = pos + 3 const end = state.skipSpacesBack(max, pos) const rawPath = state.src.slice(start, end).trim().replace(/^@/, root) - const filename = rawPath.split(/[{\s]/).shift() + const filename = rawPath.split(/{/).shift().trim() const meta = rawPath.replace(filename, '') state.line = startLine + 1 From 6af496d986b70535cfaab73e696e1f699e8e7ced Mon Sep 17 00:00:00 2001 From: Nick Evans Date: Wed, 3 Apr 2019 11:18:19 -0500 Subject: [PATCH 2/2] Add tests for snippets not splitting paht on space --- .../__tests__/__snapshots__/snippet.spec.js.snap | 10 ++++++++++ .../fragments/code-snippet-with-space-in-path.md | 1 + .../__tests__/fragments/snippet with spaces.js | 3 +++ packages/@vuepress/markdown/__tests__/snippet.spec.js | 6 ++++++ 4 files changed, 20 insertions(+) create mode 100644 packages/@vuepress/markdown/__tests__/fragments/code-snippet-with-space-in-path.md create mode 100644 packages/@vuepress/markdown/__tests__/fragments/snippet with spaces.js diff --git a/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap b/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap index 1514907d3b..d62e87224e 100644 --- a/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap +++ b/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap @@ -1,5 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`snippet import snipets when the file has a space in the file path 1`] = ` +
+
 
+
 
+
 

+
export default function () { +// .. +} +`; + exports[`snippet import snippet 1`] = `
export default function () {
   // ..
diff --git a/packages/@vuepress/markdown/__tests__/fragments/code-snippet-with-space-in-path.md b/packages/@vuepress/markdown/__tests__/fragments/code-snippet-with-space-in-path.md
new file mode 100644
index 0000000000..659cb2586d
--- /dev/null
+++ b/packages/@vuepress/markdown/__tests__/fragments/code-snippet-with-space-in-path.md
@@ -0,0 +1 @@
+<<< @/packages/@vuepress/markdown/__tests__/fragments/snippet with spaces.js {1-3}
diff --git a/packages/@vuepress/markdown/__tests__/fragments/snippet with spaces.js b/packages/@vuepress/markdown/__tests__/fragments/snippet with spaces.js
new file mode 100644
index 0000000000..575039d1ec
--- /dev/null
+++ b/packages/@vuepress/markdown/__tests__/fragments/snippet with spaces.js	
@@ -0,0 +1,3 @@
+export default function () {
+  // ..
+}
diff --git a/packages/@vuepress/markdown/__tests__/snippet.spec.js b/packages/@vuepress/markdown/__tests__/snippet.spec.js
index bd3a23cfae..4a2c65f8fe 100644
--- a/packages/@vuepress/markdown/__tests__/snippet.spec.js
+++ b/packages/@vuepress/markdown/__tests__/snippet.spec.js
@@ -24,4 +24,10 @@ describe('snippet', () => {
     const output = mdH.render(input)
     expect(output).toMatchSnapshot()
   })
+
+  test('import snipets when the file has a space in the file path', () => {
+    const input = getFragment(__dirname, 'code-snippet-with-space-in-path.md')
+    const output = mdH.render(input)
+    expect(output).toMatchSnapshot()
+  })
 })