Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions sjsonnet/src-jvm-native/sjsonnet/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ final case class Config(
doc = """If set, reverses the import order of specified jpaths (so that the rightmost wins)"""
)
reverseJpathsPriority: Flag = Flag(),
@arg(
name = "max-parser-recursion-depth",
doc =
"Set maximum parser recursion depth to prevent stack overflow from deeply nested structures"
)
maxParserRecursionDepth: Int = 1000,
@arg(
doc = "The jsonnet file you wish to evaluate",
positional = true
Expand Down
3 changes: 2 additions & 1 deletion sjsonnet/src-jvm-native/sjsonnet/SjsonnetMainBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ object SjsonnetMainBase {
settings = new Settings(
preserveOrder = config.preserveOrder.value,
strict = config.strict.value,
throwErrorForInvalidSets = config.throwErrorForInvalidSets.value
throwErrorForInvalidSets = config.throwErrorForInvalidSets.value,
maxParserRecursionDepth = config.maxParserRecursionDepth
),
storePos = (position: Position) => if (config.yamlDebug.value) currentPos = position else (),
logger = warnLogger,
Expand Down
5 changes: 3 additions & 2 deletions sjsonnet/src/sjsonnet/Importer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class CachedResolver(
internedStaticFieldSets: mutable.HashMap[
Val.StaticObjectFieldSet,
java.util.LinkedHashMap[String, java.lang.Boolean]
])
],
settings: Settings = Settings.default)
extends CachedImporter(parentImporter) {

def parse(path: Path, content: ResolvedFile)(implicit
Expand All @@ -214,7 +215,7 @@ class CachedResolver(
(path, content.contentHash()), {
val parsed = fastparse.parse(
content.getParserInput(),
new Parser(path, internedStrings, internedStaticFieldSets).document(_)
new Parser(path, internedStrings, internedStaticFieldSets, settings).document(_)
) match {
case f @ Parsed.Failure(_, _, _) =>
val traced = f.trace()
Expand Down
3 changes: 2 additions & 1 deletion sjsonnet/src/sjsonnet/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class Interpreter(
importer,
parseCache,
internedStrings,
internedStaticFieldSets
internedStaticFieldSets,
settings
) {
override def process(expr: Expr, fs: FileScope): Either[Error, (Expr, FileScope)] = {
handleException(
Expand Down
Loading