* Extract {% schema %}...{% endschema %} blocks
(fileNodeId: string)
| 397 | * Extract {% schema %}...{% endschema %} blocks |
| 398 | */ |
| 399 | private extractSchema(fileNodeId: string): void { |
| 400 | // Match {% schema %}...{% endschema %} |
| 401 | const schemaRegex = /\{%[-]?\s*schema\s*[-]?%\}([\s\S]*?)\{%[-]?\s*endschema\s*[-]?%\}/g; |
| 402 | let match; |
| 403 | |
| 404 | while ((match = schemaRegex.exec(this.source)) !== null) { |
| 405 | // A schema inside {% comment %} or {% raw %} is an example, not the |
| 406 | // section's: look again after that region ends. |
| 407 | const silent = this.silentRegionAt(match.index); |
| 408 | if (silent) { |
| 409 | schemaRegex.lastIndex = silent[1]; |
| 410 | continue; |
| 411 | } |
| 412 | const [fullMatch, schemaContent] = match; |
| 413 | const startLine = this.getLineNumber(match.index); |
| 414 | const endLine = this.getLineNumber(match.index + fullMatch.length); |
| 415 | |
| 416 | // Try to parse the schema JSON to get the name |
| 417 | let schemaName = 'schema'; |
| 418 | try { |
| 419 | const schemaJson = JSON.parse(schemaContent!); |
| 420 | if (schemaJson.name) { |
| 421 | // Shopify schema names can be translation objects like {"en": "...", "fr": "..."} |
| 422 | schemaName = typeof schemaJson.name === 'string' |
| 423 | ? schemaJson.name |
| 424 | : schemaJson.name.en || Object.values(schemaJson.name)[0] as string || 'schema'; |
| 425 | } |
| 426 | } catch { |
| 427 | // Schema isn't valid JSON, use default name |
| 428 | } |
| 429 | |
| 430 | // Create a node for the schema |
| 431 | const nodeId = this.nodeIds.generate(this.filePath, 'constant', `schema:${schemaName}`, startLine, match.index - this.getLineStart(startLine)); |
| 432 | |
| 433 | const node: Node = { |
| 434 | id: nodeId, |
| 435 | kind: 'constant', |
| 436 | name: schemaName, |
| 437 | qualifiedName: `${this.filePath}::schema:${schemaName}`, |
| 438 | filePath: this.filePath, |
| 439 | language: 'liquid', |
| 440 | startLine, |
| 441 | endLine, |
| 442 | startColumn: match.index - this.getLineStart(startLine), |
| 443 | endColumn: 0, |
| 444 | // SECURITY (#383): don't dump the raw {% schema %} JSON (section settings |
| 445 | // + default values) into the docstring — the schema name is already in |
| 446 | // `name`, so the data block adds nothing but a potential leak of any |
| 447 | // IDs/endpoints/keys a developer placed in setting defaults. |
| 448 | updatedAt: Date.now(), |
| 449 | }; |
| 450 | |
| 451 | this.nodes.push(node); |
| 452 | |
| 453 | // Add containment edge from file |
| 454 | this.edges.push({ |
| 455 | source: fileNodeId, |
| 456 | target: nodeId, |
no test coverage detected