From f908c10d62fc1fa3815569aefb31c6db19111043 Mon Sep 17 00:00:00 2001 From: xuchaoying Date: Fri, 2 Aug 2019 11:50:59 +0800 Subject: [PATCH] fix(config): fix parse plugin querystring with dot string --- .../svrx/__tests__/spec/svrx.configure.js | 22 ++++++++++++++++--- packages/svrx/lib/configure/index.js | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/svrx/__tests__/spec/svrx.configure.js b/packages/svrx/__tests__/spec/svrx.configure.js index 58572ef8..e91ee9d6 100644 --- a/packages/svrx/__tests__/spec/svrx.configure.js +++ b/packages/svrx/__tests__/spec/svrx.configure.js @@ -185,13 +185,10 @@ describe('CLI Config', () => { const server = createServer({}, { plugin: [ 'wrong@1?foo=bar', - 'wrong2?foo&bar=foo', ], }); const wrongPlugin = server.config.getPlugin('wrong'); - const wrongPlugin2 = server.config.getPlugin('wrong2'); expect(wrongPlugin).to.be(undefined); - expect(wrongPlugin2).to.be(undefined); }); }); @@ -228,6 +225,25 @@ describe('CLI Config', () => { const testPlugin = server.config.getPlugin('test'); expect(testPlugin.get('null')).to.equal(null); }); + + it('should parse string with dot', () => { + const server = createServer({}, { + plugin: 'webpack?file=custom.config.js', + }); + const testPlugin = server.config.getPlugin('webpack'); + expect(testPlugin.get('file')).to.equal('custom.config.js'); + }); + + it('should parse single param to empty string', () => { + const server = createServer({}, { + plugin: [ + 'test?foo&bar=foo', + ], + }); + const plugin = server.config.getPlugin('test'); + expect(plugin.get('foo')).to.eql(''); + expect(plugin.get('bar')).to.eql('foo'); + }); }); describe('add plugin with shortcut', () => { diff --git a/packages/svrx/lib/configure/index.js b/packages/svrx/lib/configure/index.js index cf75519d..fc4cd209 100644 --- a/packages/svrx/lib/configure/index.js +++ b/packages/svrx/lib/configure/index.js @@ -214,7 +214,7 @@ class Configure { }); return newOps; }; - const reg = /^((@\w+\/)?\w+)(@(\d+\.\d+\.\d+))?(\?(\w+=\w+(&\w+=\w+)*))?$/; + const reg = /^((@\w+\/)?\w+)(@(\d+\.\d+\.\d+))?(\?(.*))?$/; const getPlugin = (pluginString) => { const matches = reg.exec(pluginString); if (matches) {