hardening: namespace snapshot cache keys to avoid sentinel collisions
Use 'page' and 'locator:' prefixed keys instead of raw '__page__' sentinel, preventing theoretical collision if a CSS selector equals '__page__'.
This commit is contained in:
@@ -26,9 +26,9 @@ function isRegExp(value: any): value is RegExp {
|
|||||||
|
|
||||||
function getSnapshotKey(locator: Locator | Page): string {
|
function getSnapshotKey(locator: Locator | Page): string {
|
||||||
if (isPage(locator)) {
|
if (isPage(locator)) {
|
||||||
return '__page__'
|
return 'page'
|
||||||
}
|
}
|
||||||
return locator.selector()
|
return `locator:${locator.selector()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCleanHTML(options: GetCleanHTMLOptions): Promise<string> {
|
export async function getCleanHTML(options: GetCleanHTMLOptions): Promise<string> {
|
||||||
|
|||||||
@@ -790,7 +790,7 @@ export class PlaywrightExecutor {
|
|||||||
const shouldCacheSnapshot = !frame
|
const shouldCacheSnapshot = !frame
|
||||||
// Cache keyed by locator selector so full-page and locator-scoped snapshots
|
// Cache keyed by locator selector so full-page and locator-scoped snapshots
|
||||||
// don't pollute each other's diff baselines
|
// don't pollute each other's diff baselines
|
||||||
const snapshotKey = locator ? locator.selector() : '__page__'
|
const snapshotKey = locator ? `locator:${locator.selector()}` : 'page'
|
||||||
let pageSnapshots = this.lastSnapshots.get(resolvedPage)
|
let pageSnapshots = this.lastSnapshots.get(resolvedPage)
|
||||||
if (!pageSnapshots) {
|
if (!pageSnapshots) {
|
||||||
pageSnapshots = new Map()
|
pageSnapshots = new Map()
|
||||||
|
|||||||
Reference in New Issue
Block a user