Skip to content

Commit 099024a

Browse files
committed
docs(readme): reorder the statements
closes #174
1 parent b126deb commit 099024a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ export default async (entry: Entry) => {
244244
245245
In this example, the `filter` function will only exclude entries in the HAR where the request body contains a JSON object with a password field.
246246
247-
You can also modify the entries before saving the HAR by using the transform option. This option should be set to a path to a module that exports a function, similar to the filter option, to change the Entry object as desired.
248-
The function should take an Entry object as a parameter and return the modified Entry object.
247+
You can also modify the entries before saving the HAR by using the `transform` option. This option should be set to a path to a module that exports a function, similar to the filter option, to change the Entry object as desired.
249248
250249
```js
251250
cy.recordHar({ transform: '../support/remove-sensitive-data.ts' });
@@ -256,27 +255,28 @@ Here's a simple example of what the `remove-sensitive-data.ts` module might look
256255
```ts
257256
import { Entry } from 'har-format';
258257
259-
const PASSWORD_REGEXP = /"password":.*?(?=,)/g;
258+
const PASSWORD_REGEXP = /("password":\s*")\w+("\s*)/;
260259
261260
export default async (entry: Entry) => {
262261
try {
263-
// Remove sensitive information from the request and response bodies
264-
entry.request.postData.text = entry.request.postData.text.replace(
265-
PASSWORD_REGEXP,
266-
`"password":"***"`
267-
);
268-
entry.response.content.text = entry.response.content.text.replace(
269-
PASSWORD_REGEXP,
270-
`"password":"***"`
271-
);
262+
// Remove sensitive information from the request body
263+
if (entry.request.postData?.text) {
264+
entry.request.postData.text = entry.request.postData.text.replace(
265+
PASSWORD_REGEXP,
266+
'$1***$2'
267+
);
268+
}
269+
272270
return entry;
273271
} catch {
274272
return entry;
275273
}
276274
};
277275
```
278276
279-
In this example, the transform function will replace any instances of password with `***` in both the request and response bodies of each entry.
277+
The function should take an Entry object as a parameter and return the modified.
278+
279+
In this example, the transform function will replace any occurrences of password with `***` in the request body of each entry.
280280
281281
> ✴ The plugin also supports files with `.js`, `.mjs` and `.cjs` extensions.
282282

0 commit comments

Comments
 (0)