`segments` renders NaN for a segment whose `target_timerange` has no `start`
Summary
segmentData() in src/index.ts reads the timing fields straight off the segment:
const t = seg.target_timerange;
…
start_us: t.start,
duration_us: t.duration,
speed: seg.speed,
Timerange.start / .duration and Segment.speed are all typed as required, but
the on-disk shape is looser: a segment can omit start — its 0 default is simply
not written — and speed is absent from some segments. formatTime(undefined)
then renders NaN, s + duration renders NaN, and s.speed !== 1 is true for
undefined, so the speed column prints undefinedx:
ID Type Start -End Dur Spd Label
62a041c7 text NaN:00NaN-NaN:00NaN 3.00s undefinedx smoke-test
The same value reaches the JSON result as "start_us": null, so a caller that
does arithmetic on it gets NaN too.
Reproduction
Any project holding such a segment. It was measured on a real JianYing 9.0.0
(Windows) project that the app opens and edits normally — that capture is in
review as test/fixtures/jianying-9-0-0-windows/ (the smoke-test segment
carries {"duration":3000000} and no speed, while the smoke-cta-default
segment beside it carries both).
Minimal form, from the repo's own fixture:
cp test/draft_content.json /tmp/p.json
node -e 'const fs=require("fs");const d=JSON.parse(fs.readFileSync("/tmp/p.json"));
const s=d.tracks.flatMap(t=>t.segments).find(x=>x.id.startsWith("aaaaaa01"));
delete s.target_timerange.start; delete s.speed; fs.writeFileSync("/tmp/p.json",JSON.stringify(d));'
node dist/index.js segments /tmp/p.json -H # → NaN:00NaN / undefinedx
node dist/index.js segments /tmp/p.json # → "start_us": null
Which side should be fixed
The read side. Both writers that could be reached in isolation write start:
add-textatstart=0writestarget_timerange: {"start":0,"duration":…}(verified twice, including in a fresh draft)initseeds an empty draft, so it does not reintroduce a partial segment
so there is no reproducible writer to blame here, and a reader that tolerates the
shape fixes every table at once. The fields fall back to 0, 0 and 1, which
is what the app itself treats them as.
Proposed fix
Default the three values in segmentData — the single source for the segments
table, the JSON result and the text-only table. Test: delete start and speed
from the fixture, assert the -H output contains neither NaN nor undefined
and the JSON reports the defaults.
Patch: submitted as a PR from the same batch.
Thanks for catching this! Defaulting the missing fields on read makes sense, and #149 includes regression coverage for the reported failure. Keeping this open until that fix passes CI and lands.