Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/profile-logic/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,23 @@ export function sanitizePII(
maybePIIToBeRemoved: RemoveProfileInformation | null,
markerSchemaByName: MarkerSchemaByName
): SanitizeProfileResult {
// FIXME: Currently we always sanitize the source contents while publishing.
// But we should have a sharing option in the publish panel to be able to
// include sources. This needs to happen before the early return below, so
// that the source contents are removed even when no other PII removal is
// requested.
const unconditionallySanitizedShared = {
...profile.shared,
sources: {
...profile.shared.sources,
content: Array(profile.shared.sources.content.length).fill(null),
},
};

if (maybePIIToBeRemoved === null) {
// Nothing is sanitized.
// Nothing else is sanitized, but the source contents are still removed.
return {
profile,
profile: { ...profile, shared: unconditionallySanitizedShared },
isSanitized: false,
translationMaps: null,
committedRanges: null,
Expand Down Expand Up @@ -122,18 +135,10 @@ export function sanitizePII(
}
const stringTable = StringTable.withBackingArray(stringArray);
const newShared = {
...profile.shared,
...unconditionallySanitizedShared,
stringArray,
};

// FIXME: Currently we always sanitize the source contents while publishing.
// But we should have a sharing option in the publish panel to be able to
// include sources.
newShared.sources = {
...newShared.sources,
content: Array(newShared.sources.content.length).fill(null),
};

let stackFlags: Uint8Array | null = null;

if (windowIdFromPrivateBrowsing.size > 0) {
Expand Down
17 changes: 17 additions & 0 deletions src/test/unit/sanitize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1275,4 +1275,21 @@ describe('sanitizePII', function () {
'file2.js'
);
});

it('always removes source contents even when no PII removal is requested', function () {
const { profile } = getProfileFromTextSamples(`A[file:file1.js]`);
// There should be only one source.
expect(profile.shared.sources.content.length).toEqual(1);
// Pretend the source content have been loaded.
profile.shared.sources.content[0] = 'source code';

// A null `RemoveProfileInformation` means the user kept all sharing options
// checked, so no other sanitization happens.
const { profile: sanitizedProfile } = sanitizePII(profile, [], null, {});

expect(sanitizedProfile.shared.sources.content.length).toEqual(
profile.shared.sources.content.length
);
expect(sanitizedProfile.shared.sources.content[0]).toBe(null);
});
});
Loading