Skip to content

Commit

Permalink
Fix up spec version handling
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jan 13, 2023
1 parent d772d8a commit 63428e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 8 additions & 3 deletions ext/java/org/jruby/ext/psych/PsychEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,18 @@ public IRubyObject start_document(ThreadContext context, IRubyObject _version, I
TypeConverter.checkType(context, _version, arrayClass);

RubyArray versionAry = _version.convertToArray();
Optional<SpecVersion> specVersion;
if (versionAry.size() == 2) {
int versionInt0 = versionAry.eltInternal(0).convertToInteger().getIntValue();
int versionInt1 = versionAry.eltInternal(1).convertToInteger().getIntValue();

if (versionInt0 != 1 || versionInt1 != 2) {
// throw runtime.newArgumentError("invalid YAML version: " + versionAry);
if (versionInt0 != 1) {
throw runtime.newArgumentError("invalid YAML version: " + versionAry);
}

specVersion = Optional.of(new SpecVersion(versionInt0, versionInt1));
} else {
specVersion = Optional.empty();
}

Map<String, String> tagsMap = new HashMap<>();
Expand All @@ -171,7 +176,7 @@ public IRubyObject start_document(ThreadContext context, IRubyObject _version, I
}
}

DocumentStartEvent event = new DocumentStartEvent(!implicitBool, Optional.empty(), tagsMap, NULL_MARK, NULL_MARK);
DocumentStartEvent event = new DocumentStartEvent(!implicitBool, specVersion, tagsMap, NULL_MARK, NULL_MARK);
emit(context, event);
return this;
}
Expand Down
9 changes: 5 additions & 4 deletions ext/java/org/jruby/ext/psych/PsychParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,11 @@ public IRubyObject parse(ThreadContext context, IRubyObject handler, IRubyObject

private void handleDocumentStart(ThreadContext context, DocumentStartEvent dse, IRubyObject handler) {
Ruby runtime = context.runtime;
SpecVersion _version = dse.getSpecVersion().orElse(new SpecVersion(1, 2));
IRubyObject version = _version == null ?
RubyArray.newArray(runtime) :
RubyArray.newArray(runtime, runtime.newFixnum(_version.getMajor()), runtime.newFixnum(_version.getMinor()));

Optional<SpecVersion> specVersion = dse.getSpecVersion();
IRubyObject version = specVersion.isPresent() ?
RubyArray.newArray(runtime, runtime.newFixnum(specVersion.get().getMajor()), runtime.newFixnum(specVersion.get().getMinor())) :
RubyArray.newEmptyArray(runtime);

Map<String, String> tagsMap = dse.getTags();
RubyArray tags = RubyArray.newArray(runtime);
Expand Down

0 comments on commit 63428e3

Please sign in to comment.