Skip to content

Commit fcef3a5

Browse files
committed
fix(isTypedList): validate property syntax
1 parent 02d53de commit fcef3a5

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/utils/queries/constants.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
// This is the perma-link within the API docs that reference the Stability Index
44
export const DOC_API_STABILITY_SECTION_REF_URL =
55
'documentation.html#stability-index';
6+
7+
export const VALID_JAVASCRIPT_PROPERTY = /^[a-z0-9$_]+$/i;

src/utils/queries/index.mjs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import { u as createTree } from 'unist-builder';
44
import { SKIP } from 'unist-util-visit';
55

6-
import { DOC_API_STABILITY_SECTION_REF_URL } from './constants.mjs';
6+
import {
7+
DOC_API_STABILITY_SECTION_REF_URL,
8+
VALID_JAVASCRIPT_PROPERTY,
9+
} from './constants.mjs';
710
import {
811
extractYamlContent,
912
parseHeadingIntoMetadata,
@@ -278,15 +281,15 @@ createQueries.UNIST = {
278281
const [node, ...contentNodes] =
279282
list?.children?.[0]?.children?.[0]?.children ?? [];
280283

281-
// Exit if no content nodes
282-
if (!node) {
284+
const possibleProperty = node?.value?.trimStart();
285+
286+
// Exit if no content in node (or if no node exists)
287+
if (!possibleProperty) {
283288
return false;
284289
}
285290

286291
// Check for other starters
287-
if (
288-
node.value?.trimStart().match(createQueries.QUERIES.typedListStarters)
289-
) {
292+
if (possibleProperty.match(createQueries.QUERIES.typedListStarters)) {
290293
return true;
291294
}
292295

@@ -298,7 +301,8 @@ createQueries.UNIST = {
298301
// Check for inline code + space + type link pattern
299302
if (
300303
node.type === 'inlineCode' &&
301-
contentNodes[0]?.value.trim() === '' &&
304+
possibleProperty.match(VALID_JAVASCRIPT_PROPERTY) &&
305+
contentNodes[0]?.value?.trim() === '' &&
302306
contentNodes[1]?.type === 'link' &&
303307
contentNodes[1]?.children?.[0]?.value?.[0] === '<'
304308
) {

0 commit comments

Comments
 (0)