diff --git a/lib/dash/segment_template.js b/lib/dash/segment_template.js
index 8709dda1c7..daf7145435 100644
--- a/lib/dash/segment_template.js
+++ b/lib/dash/segment_template.js
@@ -102,11 +102,23 @@ shaka.dash.SegmentTemplate = class {
const periodEnd = context.periodInfo.duration ?
context.periodInfo.start + context.periodInfo.duration : Infinity;
- // Don't fit live content, since it might receive more segments.
- // Unless that live content is multi-period; it's safe to fit every period
- // but the last one, since only the last period might receive new
- // segments.
- const shouldFit = periodEnd != Infinity;
+ /* When to fit segments. All refactors should honor/update this table:
+ *
+ * | dynamic | infinite | last | should | notes |
+ * | | period | period | fit | |
+ * | ------- | -------- | ------ | ------ | ------------------------- |
+ * | F | F | X | T | typical VOD |
+ * | F | T | X | X | impossible: infinite VOD |
+ * | T | F | F | T | typical live, old period |
+ * | T | F | T | F | typical IPR |
+ * | T | T | F | X | impossible: old, infinite |
+ * | T | T | T | F | typical live, new period |
+ */
+
+ // We never fit the final period of dynamic content, which could be
+ // infinite live (with no limit to fit to) or IPR (which would expand the
+ // most recent segment to the end of the presentation).
+ const shouldFit = !(context.dynamic && context.periodInfo.isLastPeriod);
if (segmentIndex) {
if (shouldFit) {
diff --git a/test/dash/dash_parser_manifest_unit.js b/test/dash/dash_parser_manifest_unit.js
index c462f7fad4..e3505d7f64 100644
--- a/test/dash/dash_parser_manifest_unit.js
+++ b/test/dash/dash_parser_manifest_unit.js
@@ -195,42 +195,6 @@ describe('DashParser Manifest', () => {
}));
});
- it('rejects periods after one without duration', async () => {
- const periodContents = [
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ].join('\n');
- const template = [
- '',
- ' ',
- '%(periodContents)s',
- ' ',
- ' ',
- '%(periodContents)s',
- ' ',
- '',
- ].join('\n');
- const source = sprintf(template, {periodContents: periodContents});
-
- fakeNetEngine.setResponseText('dummy://foo', source);
- /** @type {shaka.extern.Manifest} */
- const manifest = await parser.start('dummy://foo', playerInterface);
- const video = manifest.variants[0].video;
- await video.createSegmentIndex();
-
- // The first period has a segment from 0-10.
- // With the second period skipping, we should fail to find a segment at 10.
- expect(video.segmentIndex.find(0)).not.toBe(null);
- expect(video.segmentIndex.find(10)).toBe(null);
- });
-
it('calculates Period times when missing', async () => {
const periodContents = [
' ',