Skip to content

Commit 5f7dade

Browse files
authored
Merge pull request #1817 from equalizedigital/william/pro-1168-audio-block-detected-as-video-block-resulting-in-video-is
PRO-1168: fix: don't flag .ogg audio as video content in video_present rule
2 parents 0c5c998 + e770024 commit 5f7dade

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

src/pageScanner/checks/is-video-detected.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,33 @@ export default {
3333
}
3434
}
3535

36+
// .ogg is the Ogg Vorbis audio extension, but the Ogg container can also carry
37+
// Theora video, so it stays in videoExtensions. To avoid flagging ordinary Ogg
38+
// Vorbis audio (e.g. the Gutenberg Audio block), only count a .ogg match as video
39+
// when it isn't attached to an <audio> element or one of its <source> children.
40+
const isInAudioContainer = tag === 'audio' || ( tag === 'source' &&
41+
node.parentNode &&
42+
node.parentNode.nodeName.toLowerCase() === 'audio' );
43+
44+
const srcLower = src.toLowerCase();
45+
const dataLower = data.toLowerCase();
46+
3647
const matchesExtension = videoExtensions.some( ( ext ) => {
37-
const srcLower = src.toLowerCase();
38-
const dataLower = data.toLowerCase();
3948
// Check if the extension is at the end of the string or followed by a query parameter
40-
return (
49+
const matches = (
4150
( srcLower.endsWith( ext ) || srcLower.includes( ext + '?' ) ) ||
4251
( dataLower.endsWith( ext ) || dataLower.includes( ext + '?' ) )
4352
);
53+
54+
if ( matches && ext === '.ogg' && isInAudioContainer ) {
55+
return false;
56+
}
57+
58+
return matches;
4459
} );
4560

4661
const matchesKeyword = videoKeywords.some( ( keyword ) =>
47-
src.toLowerCase().includes( keyword )
62+
srcLower.includes( keyword )
4863
);
4964

5065
const matchesType = type.toLowerCase().startsWith( 'video/' );

tests/jest/rules/videoElementPresent.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ describe( 'video_present rule', () => {
101101
html: '<video><source src="movie.MP4"></video>',
102102
shouldPass: false,
103103
},
104+
{
105+
name: 'detects .ogg file used as a native <video> element src',
106+
html: '<video src="movie.ogg" controls></video>',
107+
shouldPass: false,
108+
},
109+
{
110+
name: 'detects .ogg source that is not inside an <audio> element',
111+
html: '<source src="clip.ogg">',
112+
shouldPass: false,
113+
},
104114

105115
// Should not trigger violations
106116
{
@@ -135,6 +145,26 @@ describe( 'video_present rule', () => {
135145
html: '<audio controls><source src="sound.mp3" type="audio/mpeg"></audio>',
136146
shouldPass: true,
137147
},
148+
{
149+
// Direct/minimal case: the <audio> element itself has a .ogg src, exercising the
150+
// `tag === 'audio'` path in is-video-detected.js without any wrapping markup.
151+
name: 'does not detect a plain <audio> element with a .ogg src',
152+
html: '<audio controls src="simple-guitar-melody.ogg"></audio>',
153+
shouldPass: true,
154+
},
155+
{
156+
// Regression test for https://github.com/equalizedigital/accessibility-checker/issues/1816 (PRO-1168).
157+
// The Gutenberg Audio block's default sample audio is an .ogg (Ogg Vorbis) file, which was
158+
// being misidentified as video content because .ogg is also a valid Ogg Theora video extension.
159+
name: 'does not detect .ogg audio file in a <figure class="wp-block-audio"> Audio block',
160+
html: '<figure class="wp-block-audio"><audio controls src="simple-guitar-melody.ogg"></audio><figcaption>Simple Guitar Melody</figcaption></figure>',
161+
shouldPass: true,
162+
},
163+
{
164+
name: 'does not detect .ogg source element inside an <audio> element',
165+
html: '<audio controls><source src="simple-guitar-melody.ogg" type="audio/ogg"></audio>',
166+
shouldPass: true,
167+
},
138168
{
139169
name: 'does not detect YouTube API script tag',
140170
html: '<script type="text/javascript" src="https://www.youtube.com/iframe_api?ver=1.2.6" id="youtube-scripts-js"></script>',

0 commit comments

Comments
 (0)