Repository navigation
Update vmt.cc - #1941
Update vmt.cc#1941rjksmith wants to merge 2 commits into
Conversation
Refined regex for VMT timestamp
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 533747f1c2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| static uint32_t parse_vmt_timestamp(const std::string& vmt_time) | ||
| { | ||
| std::regex pattern(R"(-?((\d*):)?(\d\d):(\d\d)(\.(\d*))?)"); | ||
| std::regex pattern(R"(-?((\d{2,}):)?(\d{2}):(\d{2})(\.(\d{3}))?)"); |
There was a problem hiding this comment.
Return BAD for newly rejected fractional timestamps
When a cue uses a fractional field of any other length (for example 00:01.12), pattern_cue still accepts it, but this stricter regex no longer matches it. parse_vmt_timestamp therefore returns 0 from its no-match path instead of reaching the existing length check and returning BAD_VMT_TIMESTAMP as before; the encoder can then merge the malformed cue into the time-zero packet rather than skipping it with the bad-timestamp diagnostic. Preserve the invalid-timestamp sentinel for these newly rejected forms.
Useful? React with 👍 / 👎.
I think its point was different. I asked it for a more detailed review. The tightened pattern matches the WebVMT timestamp syntax (hours two or more digits, minutes and seconds exactly two, thousandths exactly three). One follow-up is needed in
A return value of Suggested fix: return the sentinel on no-match and drop the now-dead length check. if (!std::regex_match(vmt_time, match, pattern)) {
- return 0; // no match
+ return BAD_VMT_TIMESTAMP;
}
@@
- if (fs != "") {
- if (fs.length() == 3) {
- ms = std::stoi(fs);
- }
- else {
- return BAD_VMT_TIMESTAMP; // invalid
- }
- }
+ if (fs != "") {
+ ms = std::stoi(fs); // the pattern guarantees exactly three digits
+ }The only caller is the cue loop, and its cue regex only passes strings of digits, colons, dots and a leading minus, so nothing depends on Two minor notes on the pattern itself, no change required:
|
Refined regex for VMT timestamp to strictly match spec
Yes. I concur with both changes. The former change addresses an existing problem that was masked by the relaxed syntax check.
Omitting cue start time is an error, so that new behaviour is correct. Omitting cue end time is permitted for unbounded cues, but is already handled correctly elsewhere.
I agree. I'd spotted the former, though not the latter.
I've updated the regex to reflect this and trialled that revised syntax in the vmttool tests which continue to pass. I think this is an improvement that reflects the specification more accurately. Many thanks for your help. |
Minutes and seconds must be exactly two digits, the fraction is mandatory and exactly three digits (milliseconds), hours are one or more digits as accepted by the WebVMT timestamp parsing algorithm. Squashed from PR #1941.
|
Thanks Rob, merged. I squashed your two commits into 4d2daff (author preserved) and added a few commits on top, so GitHub shows this PR as closed rather than merged. Follow-ups on
About 906e59b: while reviewing the rest of the file I found that
The new code reads the file whole and accepts CR, LF and CRLF plus a BOM, treats any line containing Behaviour changes you may notice in your vmttool tests:
The documented rules are unchanged: end times ignored, same start time merged, negative timestamps are zero. It would be great if you could run your vmttool tests against master and tell me if anything regressed. |
|
That's a great improvement. Many thanks for your support and feedback. |
Refined regex for VMT timestamp