Skip to content

Commit 317953b

Browse files
adamalstonjennifer-shehaneAtofStryker
authored
fix: update fixture cache to prevent encoding conflicts (#32151)
* fix: update fixture cache to prevent encoding conflicts * feat: add changelog entry * empty commmit * refactor: update separator * Update packages/driver/src/cy/commands/fixtures.ts --------- Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Bill Glesias <[email protected]>
1 parent 4205770 commit 317953b

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ _Released 8/12/2025 (PENDING)_
77

88
- Fixed an issue where Angular legacy `Output()` decorators were broken when making component instance field references safe. Fixes [#32137](https://github.com/cypress-io/cypress/issues/32137).
99
- Upgraded `tmp` from `~0.2.3` to `~0.2.4`. This removes the [CVE-2025-54798](https://github.com/advisories/GHSA-52f5-9888-hmc6) vulnerability being reported in security scans. Addresses [#32176](https://github.com/cypress-io/cypress/issues/32176).
10+
- Fixed an issue where `.fixture()` calls with different encoding options would return inconsistent content based on execution order. Fixes [#32138](https://github.com/cypress-io/cypress/issues/32138).
1011

1112
## 14.5.4
1213

packages/driver/cypress/e2e/commands/fixtures.cy.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,26 @@ describe('src/cy/commands/fixtures', () => {
265265
})
266266
})
267267
})
268+
269+
it('should respect encoding specification', () => {
270+
const fixture = 'comma-separated.csv'
271+
272+
cy.fixture(fixture, 'base64').then((content) => {
273+
cy.wrap(content).should('eq', 'T25lLFR3byxUaHJlZQoxLDIsMwo=')
274+
cy.wrap(content).as('base64')
275+
})
276+
277+
cy.fixture(fixture).then((content) => {
278+
cy.wrap(content).should('eq', 'One,Two,Three\n1,2,3\n')
279+
cy.wrap(content).as('utf8')
280+
})
281+
282+
cy.get('@base64').then((base64) => {
283+
cy.get('@utf8').then((utf8) => {
284+
cy.wrap(base64).should('not.eq', utf8)
285+
})
286+
})
287+
})
268288
})
269289
})
270290
})

packages/driver/src/cy/commands/fixtures.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,6 @@ export default (Commands, Cypress, cy, state, config) => {
2828
$errUtils.throwErrByPath('fixture.set_to_false')
2929
}
3030

31-
// if we already have cached
32-
// this fixture then just return it
33-
34-
// always return a promise here
35-
// to make our interface consistent
36-
// for use by other code
37-
const resp = cache[fixture]
38-
39-
if (resp) {
40-
// clone the object first to prevent
41-
// accidentally mutating the one in the cache
42-
return Promise.resolve(clone(resp))
43-
}
44-
4531
let options: Record<string, any> = {}
4632

4733
if (_.isObject(args[0])) {
@@ -54,6 +40,14 @@ export default (Commands, Cypress, cy, state, config) => {
5440
options.encoding = args[0]
5541
}
5642

43+
const cacheKey = `${fixture}\u0000${options.encoding || ''}`
44+
const cachedContent = cache[cacheKey]
45+
46+
if (cachedContent) {
47+
// Clone the cached content to prevent accidental mutation.
48+
return Promise.resolve(clone(cachedContent))
49+
}
50+
5751
const timeout = options.timeout ?? Cypress.config('responseTimeout')
5852

5953
// need to remove the current timeout
@@ -81,7 +75,7 @@ export default (Commands, Cypress, cy, state, config) => {
8175

8276
// add the fixture to the cache
8377
// so it can just be returned next time
84-
cache[fixture] = response
78+
cache[cacheKey] = response
8579

8680
// Add the filename as a symbol, in case we need it later (such as when storing an alias)
8781
state('current').set('fileName', basename(fixture))

0 commit comments

Comments
 (0)