Skip to content

Commit

Permalink
[testharness.js] Fix issue caused when path contains full stop charac…
Browse files Browse the repository at this point in the history
…ters (.)

#50693

The current implementation of `get_title()` assumes that the path does not contain a full stop character.
If it does, `get_title()` would return parts of the path, in stead of the filename.
The pathname `/a.path/filename.html` would cause `get_title()` to return `.path` instead of the expected `filename`.

This change fixes the issue by trimming the path away before searching for the extension.
It maintains the current behavior, where it only keeps the first part of the filename if the filename contains multiple full stop characters.
`/path/filename.foo.html` still returns `filename`.
  • Loading branch information
johannesodland committed Feb 15, 2025
1 parent c9e46c0 commit d298c10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions infrastructure/testharness/full.stop/full-stop.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE HTML>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function () {
assert_equals(this.name, 'full-stop', 'Check that test name does not contain part of the path (.stop)');
});
</script>
3 changes: 2 additions & 1 deletion resources/testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -4788,7 +4788,8 @@
return META_TITLE;
}
if ('location' in global_scope && 'pathname' in location) {
return location.pathname.substring(location.pathname.lastIndexOf('/') + 1, location.pathname.indexOf('.'));
var filename = location.pathname.substring(location.pathname.lastIndexOf('/') + 1)
return filename.substring(0, filename.indexOf('.'));
}
return "Untitled";
}
Expand Down

0 comments on commit d298c10

Please sign in to comment.