Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/parser/schema_compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -222,8 +223,11 @@ func validateWithSchemaAndLocation(frontmatter map[string]any, schemaJSON, conte
var frontmatterContent string
var frontmatterStart = 2 // Default: frontmatter starts at line 2

// Sanitize the path to prevent path traversal attacks
cleanPath := filepath.Clean(filePath)

if filePath != "" {
if content, readErr := os.ReadFile(filePath); readErr == nil {
if content, readErr := os.ReadFile(cleanPath); readErr == nil {
lines := strings.Split(string(content), "\n")

// Look for frontmatter section with improved detection
Expand Down Expand Up @@ -267,7 +271,8 @@ func validateWithSchemaAndLocation(frontmatter map[string]any, schemaJSON, conte
// Create context lines around the adjusted line number in the full file
var adjustedContextLines []string
if filePath != "" {
if content, readErr := os.ReadFile(filePath); readErr == nil {
// Use the same sanitized path
if content, readErr := os.ReadFile(cleanPath); readErr == nil {
allLines := strings.Split(string(content), "\n")
// Create context around the adjusted line (±3 lines)
// The console formatter expects context to be centered around the error line
Expand Down