diff --git a/src/main/engine/ImportAnalysisEngine.ts b/src/main/engine/ImportAnalysisEngine.ts index dccbd97..7ca170c 100644 --- a/src/main/engine/ImportAnalysisEngine.ts +++ b/src/main/engine/ImportAnalysisEngine.ts @@ -146,7 +146,8 @@ export class ImportAnalysisEngine { private static readonly SHORTCODE_REGEX = /(? { const params: Record = {}; @@ -583,7 +585,10 @@ export class ImportAnalysisEngine { let match; while ((match = ImportAnalysisEngine.PARAM_REGEX.exec(paramString)) !== null) { - params[match[1]] = match[2]; + const key = match[1]; + // Value is in group 2 (double-quoted), 3 (single-quoted), or 4 (unquoted) + const value = match[2] ?? match[3] ?? match[4] ?? ''; + params[key] = value; } return params; diff --git a/tests/engine/ImportAnalysisEngine.test.ts b/tests/engine/ImportAnalysisEngine.test.ts index 8ac3920..b6dad39 100644 --- a/tests/engine/ImportAnalysisEngine.test.ts +++ b/tests/engine/ImportAnalysisEngine.test.ts @@ -709,6 +709,42 @@ describe('ImportAnalysisEngine', () => { expect(youtubeMacro?.usages[0].params.id).toBe('singlequoted'); }); + it('should handle shortcodes with unquoted parameters', async () => { + setupDbReturns([], [], []); + + const wxrData = createWxrData({ + posts: [createWxrPost({ + content: '[youtube id=abc123def4g autoplay=true][gallery columns=4]', + })], + }); + + const report = await engine.analyzeWxr(wxrData, '/test.xml'); + + const youtubeMacro = report.macros.discovered.find(m => m.name === 'youtube'); + expect(youtubeMacro?.usages[0].params.id).toBe('abc123def4g'); + expect(youtubeMacro?.usages[0].params.autoplay).toBe('true'); + + const galleryMacro = report.macros.discovered.find(m => m.name === 'gallery'); + expect(galleryMacro?.usages[0].params.columns).toBe('4'); + }); + + it('should handle mixed quoted and unquoted parameters', async () => { + setupDbReturns([], [], []); + + const wxrData = createWxrData({ + posts: [createWxrPost({ + content: '[video src="http://example.com/video.mp4" autoplay=true width=640]', + })], + }); + + const report = await engine.analyzeWxr(wxrData, '/test.xml'); + + const videoMacro = report.macros.discovered.find(m => m.name === 'video'); + expect(videoMacro?.usages[0].params.src).toBe('http://example.com/video.mp4'); + expect(videoMacro?.usages[0].params.autoplay).toBe('true'); + expect(videoMacro?.usages[0].params.width).toBe('640'); + }); + it('should not detect our internal macro format as WordPress shortcodes', async () => { setupDbReturns([], [], []);