Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1401 from atom/aw/notifications-purified
Browse files Browse the repository at this point in the history
DOMPurify is done within the notifications package
  • Loading branch information
smashwilson committed Apr 19, 2018
1 parent c52d62b commit 253712d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 29 deletions.
4 changes: 1 addition & 3 deletions lib/controllers/git-tab-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'path';
import React from 'react';
import PropTypes from 'prop-types';
import {autobind} from 'core-decorators';
import createDOMPurify from 'dompurify';

import yubikiri from 'yubikiri';

Expand All @@ -13,7 +12,6 @@ import UserStore from '../models/user-store';
import {nullBranch} from '../models/branch';
import {nullCommit} from '../models/commit';

const DOMPurify = createDOMPurify();

@ObserveModelDecorator({
getModel: props => props.repository,
Expand Down Expand Up @@ -360,7 +358,7 @@ export default class GitTabController extends React.Component {
} catch (e) {
if (e.code === 'EDIRTYSTAGED') {
this.props.notificationManager.addError(
DOMPurify.sanitize(`Cannot abort because ${e.path} is both dirty and staged.`),
`Cannot abort because ${e.path} is both dirty and staged.`,
{dismissable: true},
);
} else {
Expand Down
14 changes: 5 additions & 9 deletions lib/controllers/root-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import url from 'url';
import React from 'react';
import PropTypes from 'prop-types';
import {autobind} from 'core-decorators';
import createDOMPurify from 'dompurify';


import StatusBar from '../views/status-bar';
import Panel from '../views/panel';
Expand All @@ -27,8 +27,6 @@ import Switchboard from '../switchboard';
import {toNativePathSep, destroyFilePatchPaneItems, destroyEmptyFilePatchPaneItems} from '../helpers';
import {GitError} from '../git-shell-out-strategy';

const DOMPurify = createDOMPurify();

function getPropsFromUri(uri) {
// atom-github://file-patch/file.txt?workdir=/foo/bar/baz&stagingStatus=staged
const {protocol, hostname, pathname, query} = url.parse(uri, true);
Expand Down Expand Up @@ -397,7 +395,7 @@ export default class RootController extends React.Component {
await this.props.cloneRepositoryForProjectPath(remoteUrl, projectPath);
} catch (e) {
this.props.notificationManager.addError(
DOMPurify.sanitize(`Unable to clone ${remoteUrl}`),
`Unable to clone ${remoteUrl}`,
{detail: e.stdErr, dismissable: true},
);
} finally {
Expand All @@ -417,7 +415,7 @@ export default class RootController extends React.Component {
if (this.state.initDialogResolve) { this.state.initDialogResolve(projectPath); }
} catch (e) {
this.props.notificationManager.addError(
DOMPurify.sanitize(`Unable to initialize git repository in ${projectPath}`),
`Unable to initialize git repository in ${projectPath}`,
{detail: e.stdErr, dismissable: true},
);
} finally {
Expand Down Expand Up @@ -563,7 +561,7 @@ export default class RootController extends React.Component {
this.props.notificationManager.addError(
message,
{
description: DOMPurify.sanitize(`You have unsaved changes in:<br>${unsavedFiles}.`),
description: `You have unsaved changes in:<br>${unsavedFiles}.`,
dismissable: true,
},
);
Expand Down Expand Up @@ -659,9 +657,7 @@ export default class RootController extends React.Component {
this.props.notificationManager.addError(
'Discard history has expired.',
{
description: DOMPurify.sanitize(
`Cannot undo discard for<br>${filePathsStr}<br>Stale discard history has been deleted.`,
),
description: `Cannot undo discard for<br>${filePathsStr}<br>Stale discard history has been deleted.`,
dismissable: true,
},
);
Expand Down
13 changes: 4 additions & 9 deletions lib/get-repo-pipeline-manager.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import fs from 'fs-extra';
import createDOMPurify from 'dompurify';

import ActionPipelineManager from './action-pipeline';
import {GitError} from './git-shell-out-strategy';
import {getCommitMessagePath, getCommitMessageEditors, destroyFilePatchPaneItems} from './helpers';

const DOMPurify = createDOMPurify();

// Note: Middleware that catches errors should re-throw the errors so that they propogate
// and other middleware in the pipeline can be made aware of the errors.
// Ultimately, the views are responsible for catching the errors and handling them accordingly
Expand Down Expand Up @@ -79,10 +76,9 @@ export default function({confirm, notificationManager, workspace}) {
const lines = error.stdErr.split('\n');
const files = lines.slice(3, lines.length - 3).map(l => `\`${l.trim()}\``).join('\n');
notificationManager.addError('Pull aborted', {
description: DOMPurify.sanitize(
description:
'Local changes to the following would be overwritten by merge:<br/>' + files +
'<br/>Please commit your changes or stash them before you merge.',
),
dismissable: true,
});
} else if (/Automatic merge failed; fix conflicts and then commit the result./.test(error.stdOut)) {
Expand Down Expand Up @@ -149,12 +145,11 @@ export default function({confirm, notificationManager, workspace}) {
if (error.stdErr.match(/local changes.*would be overwritten/)) {
const files = error.stdErr.split(/\r?\n/).filter(l => l.startsWith('\t'))
.map(l => `\`${l.trim()}\``).join('<br/>');
description = DOMPurify.sanitize(
description =
'Local changes to the following would be overwritten:<br/>' + files +
'<br/>Please commit your changes or stash them.',
);
'<br/>Please commit your changes or stash them.';
} else if (error.stdErr.match(/branch.*already exists/)) {
description = DOMPurify.sanitize(`\`${branchName}\` already exists. Choose another branch name.`);
description = `\`${branchName}\` already exists. Choose another branch name.`;
} else if (error.stdErr.match(/error: you need to resolve your current index first/)) {
description = 'You must first resolve merge conflicts.';
}
Expand Down
9 changes: 2 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"compare-sets": "^1.0.1",
"core-decorators": "^0.19.0",
"diff": "3.2.0",
"dompurify": "^1.0.3",
"dugite": "^1.60.0",
"etch": "^0.12.4",
"event-kit": "^2.3.0",
Expand Down

0 comments on commit 253712d

Please sign in to comment.