Skip to content

Commit 63428e3

Browse files
committed
Fix up spec version handling
1 parent d772d8a commit 63428e3

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

ext/java/org/jruby/ext/psych/PsychEmitter.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,18 @@ public IRubyObject start_document(ThreadContext context, IRubyObject _version, I
140140
TypeConverter.checkType(context, _version, arrayClass);
141141

142142
RubyArray versionAry = _version.convertToArray();
143+
Optional<SpecVersion> specVersion;
143144
if (versionAry.size() == 2) {
144145
int versionInt0 = versionAry.eltInternal(0).convertToInteger().getIntValue();
145146
int versionInt1 = versionAry.eltInternal(1).convertToInteger().getIntValue();
146147

147-
if (versionInt0 != 1 || versionInt1 != 2) {
148-
// throw runtime.newArgumentError("invalid YAML version: " + versionAry);
148+
if (versionInt0 != 1) {
149+
throw runtime.newArgumentError("invalid YAML version: " + versionAry);
149150
}
151+
152+
specVersion = Optional.of(new SpecVersion(versionInt0, versionInt1));
153+
} else {
154+
specVersion = Optional.empty();
150155
}
151156

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

174-
DocumentStartEvent event = new DocumentStartEvent(!implicitBool, Optional.empty(), tagsMap, NULL_MARK, NULL_MARK);
179+
DocumentStartEvent event = new DocumentStartEvent(!implicitBool, specVersion, tagsMap, NULL_MARK, NULL_MARK);
175180
emit(context, event);
176181
return this;
177182
}

ext/java/org/jruby/ext/psych/PsychParser.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,11 @@ public IRubyObject parse(ThreadContext context, IRubyObject handler, IRubyObject
305305

306306
private void handleDocumentStart(ThreadContext context, DocumentStartEvent dse, IRubyObject handler) {
307307
Ruby runtime = context.runtime;
308-
SpecVersion _version = dse.getSpecVersion().orElse(new SpecVersion(1, 2));
309-
IRubyObject version = _version == null ?
310-
RubyArray.newArray(runtime) :
311-
RubyArray.newArray(runtime, runtime.newFixnum(_version.getMajor()), runtime.newFixnum(_version.getMinor()));
308+
309+
Optional<SpecVersion> specVersion = dse.getSpecVersion();
310+
IRubyObject version = specVersion.isPresent() ?
311+
RubyArray.newArray(runtime, runtime.newFixnum(specVersion.get().getMajor()), runtime.newFixnum(specVersion.get().getMinor())) :
312+
RubyArray.newEmptyArray(runtime);
312313

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

0 commit comments

Comments
 (0)