Skip to content

Commit 39c1759

Browse files
adamalstonjennifer-shehaneAtofStryker
authored
fix: return raw fixture when encoding is specified (#32155)
* fix: return raw fixture when encoding is specified * revert: revert test change --------- Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Bill Glesias <[email protected]>
1 parent 317953b commit 39c1759

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
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 a specified encoding would sometimes still attempt to parse the file based on its extension. Files with an explicit encoding are now always treated as raw content. Fixes [#32139](https://github.com/cypress-io/cypress/issues/32139).
1011
- 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).
1112

1213
## 14.5.4

packages/server/lib/fixture.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,10 @@ module.exports = {
125125
},
126126

127127
parseFileByExtension (p, fixture, ext, options = {}) {
128-
// https://github.com/cypress-io/cypress/issues/1558
129-
// If the user explicitly specifies `null` as the encoding, we treat the
130-
// file as binary regardless of extension. We base64 encode them for
131-
// transmission over the websocket. There is a matching Buffer.from()
132-
// in packages/driver/src/cy/commands/fixtures.ts
133-
if (options.encoding === null) {
134-
return this.parse(p, fixture)
128+
// If an encoding is specified, return the raw file content instead of
129+
// parsing.
130+
if (typeof options.encoding !== 'undefined') {
131+
return this.parse(p, fixture, options.encoding)
135132
}
136133

137134
switch (ext) {

packages/server/test/unit/fixture_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@ describe('lib/fixture', () => {
169169
})
170170
})
171171
})
172+
173+
it('should return encoded JSON', async function () {
174+
const fixtures = [
175+
{ encoding: '', content: Buffer.from('[{"json": true}]') },
176+
{ encoding: 'base64', content: 'W3sianNvbiI6IHRydWV9XQ==' },
177+
{ encoding: 'utf8', content: '[{"json": true}]' },
178+
{ encoding: null, content: Buffer.from('[{"json": true}]') },
179+
{ encoding: undefined, content: [{ json: true }] },
180+
]
181+
182+
for (const { encoding, content } of fixtures) {
183+
const result = await fixture.get(this.fixturesFolder, 'foo', { encoding })
184+
185+
expect(result).to.deep.equal(content)
186+
}
187+
})
172188
})
173189

174190
context('js files', () => {

0 commit comments

Comments
 (0)