Skip to content

Commit

Permalink
Merge pull request #150 from Arthelon/escape-props
Browse files Browse the repository at this point in the history
"server-side dependencies such as jsesc were previously being pulled into the client bundle and not being transpiled properly. This patch should prevent this from happening."
  • Loading branch information
LordSputnik committed Dec 3, 2017
2 parents 93b67b8 + 69f4351 commit 43580a5
Show file tree
Hide file tree
Showing 29 changed files with 171 additions and 132 deletions.
3 changes: 1 addition & 2 deletions src/client/components/pages/entity/creator.js
Expand Up @@ -21,14 +21,13 @@
/* eslint strict: 0 */

import * as entityHelper from '../../../helpers/entity';
import * as propsHelper from '../../../../server/helpers/props';
import AttributeList from '../parts/attribute-list';
import EntityPage from '../../../containers/entity';
import React from 'react';
import {extractEntityProps} from '../../../helpers/props';


const {extractAttribute, getDateAttributes, getTypeAttribute} = entityHelper;
const {extractEntityProps} = propsHelper;

function CreatorPage(props) {
const {entity} = props;
Expand Down
3 changes: 1 addition & 2 deletions src/client/components/pages/entity/edition.js
Expand Up @@ -20,15 +20,14 @@
/* eslint strict: 0 */

import * as entityHelper from '../../../helpers/entity';
import * as propsHelper from '../../../../server/helpers/props';
import AttributeList from '../parts/attribute-list';
import EntityPage from '../../../containers/entity';
import FontAwesome from 'react-fontawesome';
import React from 'react';
import {extractEntityProps} from '../../../helpers/props';


const {extractAttribute, getLanguageAttribute} = entityHelper;
const {extractEntityProps} = propsHelper;

function EditionPage(props) {
const {entity} = props;
Expand Down
3 changes: 1 addition & 2 deletions src/client/components/pages/entity/publication.js
Expand Up @@ -21,14 +21,13 @@
/* eslint strict: 0 */

import * as entityHelper from '../../../helpers/entity';
import * as propsHelper from '../../../../server/helpers/props';
import AttributeList from '../parts/attribute-list';
import EntityPage from '../../../containers/entity';
import React from 'react';
import {extractEntityProps} from '../../../helpers/props';


const {getTypeAttribute, showEntityEditions} = entityHelper;
const {extractEntityProps} = propsHelper;

function PublicationPage(props) {
const {entity} = props;
Expand Down
3 changes: 1 addition & 2 deletions src/client/components/pages/entity/publisher.js
Expand Up @@ -21,16 +21,15 @@
/* eslint strict: 0 */

import * as entityHelper from '../../../helpers/entity';
import * as propsHelper from '../../../../server/helpers/props';
import AttributeList from '../parts/attribute-list';
import EntityPage from '../../../containers/entity';
import React from 'react';
import {extractEntityProps} from '../../../helpers/props';


const {
extractAttribute, getTypeAttribute, getDateAttributes, showEntityEditions
} = entityHelper;
const {extractEntityProps} = propsHelper;

function PublisherPage(props) {
const {entity} = props;
Expand Down
3 changes: 1 addition & 2 deletions src/client/components/pages/entity/work.js
Expand Up @@ -21,14 +21,13 @@
/* eslint strict: 0 */

import * as entityHelper from '../../../helpers/entity';
import * as propsHelper from '../../../../server/helpers/props';
import AttributeList from '../parts/attribute-list';
import EntityPage from '../../../containers/entity';
import React from 'react';
import {extractEntityProps} from '../../../helpers/props';


const {getLanguageAttribute, getTypeAttribute} = entityHelper;
const {extractEntityProps} = propsHelper;

function WorkPage(props) {
const {entity} = props;
Expand Down
4 changes: 2 additions & 2 deletions src/client/controllers/deletion.js
Expand Up @@ -16,18 +16,18 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import * as propHelpers from '../../server/helpers/props';
import DeletionForm from '../components/forms/deletion';
import Layout from '../containers/layout';
import React from 'react';
import ReactDOM from 'react-dom';
import {extractLayoutProps} from '../helpers/props';


const propsTarget = document.getElementById('props');
const props = propsTarget ? JSON.parse(propsTarget.innerHTML) : {};

const markup = (
<Layout {...propHelpers.extractLayoutProps(props)}>
<Layout {...extractLayoutProps(props)}>
<DeletionForm entity={props.entity}/>
</Layout>
);
Expand Down
9 changes: 6 additions & 3 deletions src/client/controllers/editor/achievement.js
Expand Up @@ -18,7 +18,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import * as propHelpers from '../../../server/helpers/props';
import {
extractEditorProps,
extractLayoutProps
} from '../../helpers/props';
import AchievementsTab from '../../components/pages/parts/editor-achievements';
import EditorContainer from '../../containers/editor';
import Layout from '../../containers/layout';
Expand All @@ -30,9 +33,9 @@ const propsTarget = document.getElementById('props');
const props = propsTarget ? JSON.parse(propsTarget.innerHTML) : {};

ReactDOM.render(
<Layout {...propHelpers.extractLayoutProps(props)}>
<Layout {...extractLayoutProps(props)}>
<EditorContainer
{...propHelpers.extractEditorProps(props)}
{...extractEditorProps(props)}
>
<AchievementsTab
achievement={props.achievement}
Expand Down
4 changes: 2 additions & 2 deletions src/client/controllers/editor/edit.js
Expand Up @@ -17,18 +17,18 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import * as propHelpers from '../../../server/helpers/props';
import Layout from '../../containers/layout';
import ProfileForm from '../../components/forms/profile';
import React from 'react';
import ReactDOM from 'react-dom';
import {extractLayoutProps} from '../../helpers/props';


const propsTarget = document.getElementById('props');
const props = propsTarget ? JSON.parse(propsTarget.innerHTML) : {};

ReactDOM.render(
<Layout {...propHelpers.extractLayoutProps(props)}>
<Layout {...extractLayoutProps(props)}>
<ProfileForm
editor={props.editor}
genders={props.genders}
Expand Down
12 changes: 8 additions & 4 deletions src/client/controllers/editor/editor.js
Expand Up @@ -17,7 +17,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import * as propHelpers from '../../../server/helpers/props';
import {
extractChildProps,
extractEditorProps,
extractLayoutProps
} from '../../helpers/props';
import EditorContainer from '../../containers/editor';
import Layout from '../../containers/layout';
import ProfileTab from '../../components/pages/parts/editor-profile';
Expand All @@ -41,15 +45,15 @@ else {
tab = (
<ProfileTab
user={props.user}
{...propHelpers.extractChildProps(props)}
{...extractChildProps(props)}
/>
);
}

const markup = (
<Layout {...propHelpers.extractLayoutProps(props)} >
<Layout {...extractLayoutProps(props)} >
<EditorContainer
{...propHelpers.extractEditorProps(props)}
{...extractEditorProps(props)}
>
{tab}
</EditorContainer>
Expand Down
11 changes: 7 additions & 4 deletions src/client/controllers/entity/entity.js
Expand Up @@ -16,7 +16,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import * as propHelpers from '../../../server/helpers/props';
import {
extractEntityProps,
extractLayoutProps
} from '../../helpers/props';
import CreatorPage from '../../components/pages/entities/creator';
import EditionPage from '../../components/pages/entities/edition';
import EntityRevisions from '../../components/pages/entity-revisions';
Expand Down Expand Up @@ -47,7 +50,7 @@ const Child = entityComponents[page] || CreatorPage;
let markup = null;
if (page === 'revisions') {
markup = (
<Layout {...propHelpers.extractLayoutProps(props)}>
<Layout {...extractLayoutProps(props)}>
<EntityRevisions
entity={props.entity}
revisions={props.revisions}
Expand All @@ -57,8 +60,8 @@ if (page === 'revisions') {
}
else {
markup = (
<Layout {...propHelpers.extractLayoutProps(props)}>
<Child {...propHelpers.extractEntityProps(props)}/>
<Layout {...extractLayoutProps(props)}>
<Child {...extractEntityProps(props)}/>
</Layout>
);
}
Expand Down
9 changes: 6 additions & 3 deletions src/client/controllers/index.js
Expand Up @@ -16,7 +16,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import * as propHelpers from '../../server/helpers/props';
import {
extractChildProps,
extractLayoutProps
} from '../helpers/props';
import AboutPage from '../../client/components/pages/about';
import ContributePage from '../../client/components/pages/contribute';
import DevelopPage from '../../client/components/pages/develop';
Expand Down Expand Up @@ -46,8 +49,8 @@ const pageMap = {
const Child = pageMap[page] || Index;

const markup = (
<Layout {...propHelpers.extractLayoutProps(props)}>
<Child {...propHelpers.extractChildProps(props)}/>
<Layout {...extractLayoutProps(props)}>
<Child {...extractChildProps(props)}/>
</Layout>
);

Expand Down
4 changes: 2 additions & 2 deletions src/client/controllers/registrationDetails.js
Expand Up @@ -17,18 +17,18 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import * as propHelpers from '../../server/helpers/props';
import Layout from '../containers/layout';
import React from 'react';
import ReactDOM from 'react-dom';
import RegistrationForm from '../components/forms/registration-details';
import {extractLayoutProps} from '../helpers/props';


const propsTarget = document.getElementById('props');
const props = propsTarget ? JSON.parse(propsTarget.innerHTML) : {};

const markup = (
<Layout {...propHelpers.extractLayoutProps(props)}>
<Layout {...extractLayoutProps(props)}>
<RegistrationForm
gender={props.gender}
genders={props.genders}
Expand Down
4 changes: 2 additions & 2 deletions src/client/controllers/revision.js
Expand Up @@ -16,17 +16,17 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import * as propHelpers from '../../server/helpers/props';
import Layout from '../containers/layout';
import React from 'react';
import ReactDOM from 'react-dom';
import RevisionPage from '../components/pages/revision';
import {extractLayoutProps} from '../helpers/props';


const propsTarget = document.getElementById('props');
const props = propsTarget ? JSON.parse(propsTarget.innerHTML) : {};
const markup = (
<Layout {...propHelpers.extractLayoutProps(props)}>
<Layout {...extractLayoutProps(props)}>
<RevisionPage
diffs={props.diffs}
revision={props.revision}
Expand Down
5 changes: 2 additions & 3 deletions src/client/controllers/search.js
Expand Up @@ -16,18 +16,17 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import * as propHelpers from '../../server/helpers/props';
import Layout from '../containers/layout';
import React from 'react';
import ReactDOM from 'react-dom';
import SearchPage from '../components/pages/search';

import {extractLayoutProps} from '../helpers/props';

const propsTarget = document.getElementById('props');
const props = propsTarget ? JSON.parse(propsTarget.innerHTML) : {};

const markup = (
<Layout {...propHelpers.extractLayoutProps(props)}>
<Layout {...extractLayoutProps(props)}>
<SearchPage initialResults={props.initialResults}/>
</Layout>
);
Expand Down
9 changes: 6 additions & 3 deletions src/client/entity-editor/controller.js
Expand Up @@ -21,8 +21,11 @@
*/

import * as helpers from './helpers';
import * as propHelpers from '../../server/helpers/props';
import {applyMiddleware, compose, createStore} from 'redux';
import {
extractChildProps,
extractLayoutProps
} from '../helpers/props';
import EntityEditor from './entity-editor';
import Immutable from 'immutable';
import Layout from '../containers/layout';
Expand Down Expand Up @@ -58,11 +61,11 @@ const store = createStore(
);

const markup = (
<Layout {...propHelpers.extractLayoutProps(rest)}>
<Layout {...extractLayoutProps(rest)}>
<Provider store={store}>
<EntityEditor
validate={getValidator(props.entityType)}
{...propHelpers.extractChildProps(rest)}
{...extractChildProps(rest)}
>
<EntitySection/>
</EntityEditor>
Expand Down
53 changes: 53 additions & 0 deletions src/client/helpers/props.js
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2017 Daniel Hsing
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import {omit, pick} from 'lodash';

const LAYOUT_PROPS = [
'hideSearch',
'homepage',
'repositoryUrl',
'requiresJS',
'siteRevision',
'user'
];

const EDITOR_PROPS = [
'editor',
'tabActive'
];

export function extractLayoutProps(props) {
return pick(props, LAYOUT_PROPS);
}

export function extractEditorProps(props) {
return pick(props, EDITOR_PROPS);
}

export function extractChildProps(props) {
return omit(props, LAYOUT_PROPS);
}

export function extractEntityProps(props) {
return {
alert: props.alert,
entity: props.entity,
identifierTypes: props.identifierTypes
};
}

0 comments on commit 43580a5

Please sign in to comment.