summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matt Kane <m@mk.gg> 2024-12-11 10:21:44 +0000
committerGravatar GitHub <noreply@github.com> 2024-12-11 10:21:44 +0000
commitb01c74aeccc4ec76b64fa75d163df58274b37970 (patch)
tree981e3a5782cd5c40b114b71837422b6b857d419c
parent97c9265754b78af12ad1e399cc75028435028dfa (diff)
downloadastro-b01c74aeccc4ec76b64fa75d163df58274b37970.tar.gz
astro-b01c74aeccc4ec76b64fa75d163df58274b37970.tar.zst
astro-b01c74aeccc4ec76b64fa75d163df58274b37970.zip
fix: strip query string before checking md extension (#12712)
-rw-r--r--.changeset/tidy-ligers-tan.md5
-rw-r--r--packages/astro/src/core/util.ts4
-rw-r--r--packages/astro/test/astro-markdown.test.js23
-rw-r--r--packages/astro/test/fixtures/astro-markdown/src/pages/false-positive.astro5
4 files changed, 35 insertions, 2 deletions
diff --git a/.changeset/tidy-ligers-tan.md b/.changeset/tidy-ligers-tan.md
new file mode 100644
index 000000000..9891877bf
--- /dev/null
+++ b/.changeset/tidy-ligers-tan.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixes a bug which misidentified pages as markdown if a query string ended in a markdown extension
diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts
index f9dd0ced8..458fb9bdc 100644
--- a/packages/astro/src/core/util.ts
+++ b/packages/astro/src/core/util.ts
@@ -18,9 +18,11 @@ export function isURL(value: unknown): value is URL {
}
/** Check if a file is a markdown file based on its extension */
export function isMarkdownFile(fileId: string, option?: { suffix?: string }): boolean {
+ // Strip query string
+ const id = fileId.split("?")[0];
const _suffix = option?.suffix ?? '';
for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
- if (fileId.endsWith(`${markdownFileExtension}${_suffix}`)) return true;
+ if (id.endsWith(`${markdownFileExtension}${_suffix}`)) return true;
}
return false;
}
diff --git a/packages/astro/test/astro-markdown.test.js b/packages/astro/test/astro-markdown.test.js
index d0a49c873..0dae61ebd 100644
--- a/packages/astro/test/astro-markdown.test.js
+++ b/packages/astro/test/astro-markdown.test.js
@@ -1,5 +1,5 @@
import assert from 'node:assert/strict';
-import { before, describe, it } from 'node:test';
+import { before, describe, it, after } from 'node:test';
import * as cheerio from 'cheerio';
import { fixLineEndings, loadFixture } from './test-utils.js';
@@ -154,4 +154,25 @@ describe('Astro Markdown', () => {
assert.ok(title.includes('import.meta.env.TITLE'));
});
});
+
+ describe('dev', () => {
+ let devServer;
+
+ before(async () => {
+ devServer = await fixture.startDevServer();
+ });
+
+ it('ignores .md extensions on query params', async () => {
+ const res = await fixture.fetch('/false-positive?page=page.md');
+ assert.ok(res.ok);
+ const html = await res.text();
+ const $ = cheerio.load(html);
+ assert.equal($('p').text(), 'the page is not markdown');
+ });
+
+ after(async () => {
+ await devServer.stop();
+ });
+
+ });
});
diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/false-positive.astro b/packages/astro/test/fixtures/astro-markdown/src/pages/false-positive.astro
new file mode 100644
index 000000000..2f39ecead
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-markdown/src/pages/false-positive.astro
@@ -0,0 +1,5 @@
+---
+let page = "not markdown"
+---
+
+<p>the page is {page}</p>