Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move sanitize so we don't import the world into every bundle #7334

Merged
merged 1 commit into from
Feb 23, 2018
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
14 changes: 0 additions & 14 deletions src/js/common/schemaform/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,17 +542,3 @@ export function getActiveChapters(formConfig, formData) {
return _.uniq(expandedPageList.map(p => p.chapterKey).filter(key => !!key && key !== 'review'));
}

export function sanitizeForm(formData) {
try {
const suffixes = ['vaFileNumber', 'first', 'last', 'accountNumber', 'socialSecurityNumber', 'dateOfBirth'];
return JSON.stringify(formData, (key, value) => {
if (value && suffixes.some(suffix => key.toLowerCase().endsWith(suffix.toLowerCase()))) {
return 'removed';
}

return value;
});
} catch (e) {
return null;
}
}
2 changes: 1 addition & 1 deletion src/js/common/schemaform/save-in-progress/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'isomorphic-fetch';
import { logOut } from '../../../login/actions';

import { removeFormApi, saveFormApi } from './api';
import { sanitizeForm } from '../helpers';
import { sanitizeForm } from '../../utils/helpers';

export const SET_SAVE_FORM_STATUS = 'SET_SAVE_FORM_STATUS';
export const SET_AUTO_SAVE_FORM_STATUS = 'SET_AUTO_SAVE_FORM_STATUS';
Expand Down
2 changes: 1 addition & 1 deletion src/js/common/schemaform/save-in-progress/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Raven from 'raven-js';
import environment from '../../helpers/environment';
import { sanitizeForm } from '../helpers';
import { sanitizeForm } from '../../utils/helpers';

export function removeFormApi(formId) {
const userToken = sessionStorage.userToken;
Expand Down
15 changes: 15 additions & 0 deletions src/js/common/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,18 @@ export function sortListByFuzzyMatch(value, list, prop = 'label') {
})
.map(sorted => sorted.original);
}

export function sanitizeForm(formData) {
try {
const suffixes = ['vaFileNumber', 'first', 'last', 'accountNumber', 'socialSecurityNumber', 'dateOfBirth'];
return JSON.stringify(formData, (key, value) => {
if (value && suffixes.some(suffix => key.toLowerCase().endsWith(suffix.toLowerCase()))) {
return 'removed';
}

return value;
});
} catch (e) {
return null;
}
}