diff --git a/services/web/app/views/layout.pug b/services/web/app/views/layout.pug index 788f5590e4..dbc090691c 100644 --- a/services/web/app/views/layout.pug +++ b/services/web/app/views/layout.pug @@ -66,17 +66,17 @@ html( jsPath: '#{jsPath}', sixpackDomain: '#{settings.sixpack.domain}' }; - window.systemMessages = !{JSON.stringify(systemMessages).replace(/\//g, '\\/')}; + window.systemMessages = !{StringHelper.stringifyJsonForScript(systemMessages)}; window.ab = {}; window.user_id = '#{getLoggedInUserId()}'; - window.ExposedSettings = JSON.parse('!{JSON.stringify(ExposedSettings).replace(/\//g, "\\/")}'); + window.ExposedSettings = JSON.parse('!{StringHelper.stringifyJsonForScript(ExposedSettings)}'); - if (typeof(settings.algolia) != "undefined") script. window.sharelatex.algolia = { app_id:'#{settings.algolia.app_id}', api_key:'#{settings.algolia.read_only_api_key}', - indexes:!{JSON.stringify(settings.algolia.indexes)} + indexes:!{StringHelper.stringifyJsonForScript(settings.algolia.indexes)} } - if (typeof(settings.templates) != "undefined") diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index 04db699119..d17a5d70aa 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -116,7 +116,7 @@ block requirejs //- We need to do .replace(/\//g, '\\/') do that '' -> '<\/script>' //- and doesn't prematurely end the script tag. script#data(type="application/json"). - !{JSON.stringify({userSettings: userSettings, user: user, trackChangesState: trackChangesState, useV2History: useV2History, enabledLinkedFileTypes: settings.enabledLinkedFileTypes, brandVariation: brandVariation}).replace(/\//g, '\\/')} + !{StringHelper.stringifyJsonForScript({ userSettings: userSettings, user: user, trackChangesState: trackChangesState, useV2History: useV2History, enabledLinkedFileTypes: settings.enabledLinkedFileTypes, brandVariation: brandVariation })} script(type="text/javascript"). window.data = JSON.parse($("#data").text()); @@ -174,14 +174,14 @@ block requirejs }; window.aceWorkerPath = "#{aceWorkerPath}"; window.pdfCMapsPath = "#{pdfCMapsPath}" - window.uiConfig = JSON.parse('!{JSON.stringify(uiConfig).replace(/\//g, "\\/")}'); + window.uiConfig = JSON.parse('!{StringHelper.stringifyJsonForScript(uiConfig)}'); //- enable doc hash checking for projects created after 2019-06-09 //- this is for a staged rollout, eventually we will turn this on for all projects window.useShareJsHash = (window.project_id > "5cfd8f700000000000000000") - if (settings.overleaf != null) script(type='text/javascript'). - window.overallThemes = JSON.parse('!{JSON.stringify(overallThemes).replace(/\//g, "\\/")}'); + window.overallThemes = JSON.parse('!{StringHelper.stringifyJsonForScript(overallThemes)}'); script( data-main=buildJsPath("ide.js", {hashedPath:false}), diff --git a/services/web/app/views/project/list.pug b/services/web/app/views/project/list.pug index 082b628ff9..bf04422188 100644 --- a/services/web/app/views/project/list.pug +++ b/services/web/app/views/project/list.pug @@ -4,11 +4,8 @@ block vars - var suppressNavContentLinks = true block content - //- We need to do .replace(/\//g, '\\/') do that '' -> '<\/script>' - //- and doesn't prematurely end the script tag. script#data(type="application/json"). - !{JSON.stringify({ projects: projects, tags: tags, notifications: notifications }).replace(/\//g, '\\/')} - + !{StringHelper.stringifyJsonForScript({ projects, tags, notifications })} script(type="text/javascript"). window.data = JSON.parse($("#data").text()); diff --git a/services/web/app/views/subscriptions/dashboard/_managed_institutions.pug b/services/web/app/views/subscriptions/dashboard/_managed_institutions.pug index 6f7dfe112a..6dffe7e90e 100644 --- a/services/web/app/views/subscriptions/dashboard/_managed_institutions.pug +++ b/services/web/app/views/subscriptions/dashboard/_managed_institutions.pug @@ -1,5 +1,5 @@ script(type='text/javascript'). - window.managedInstitutions = !{JSON.stringify(managedInstitutions)} + window.managedInstitutions = !{StringHelper.stringifyJsonForScript(managedInstitutions)} each institution in managedInstitutions p diff --git a/services/web/app/views/subscriptions/dashboard/_personal_subscription_recurly.pug b/services/web/app/views/subscriptions/dashboard/_personal_subscription_recurly.pug index 645a2e037a..7e93afac3c 100644 --- a/services/web/app/views/subscriptions/dashboard/_personal_subscription_recurly.pug +++ b/services/web/app/views/subscriptions/dashboard/_personal_subscription_recurly.pug @@ -1,7 +1,7 @@ script(src="https://js.recurly.com/v3/recurly.js") script(type='text/javascript'). window.recurlyApiKey = "!{settings.apis.recurly.publicKey}" - window.subscription = !{JSON.stringify(personalSubscription)} + window.subscription = !{StringHelper.stringifyJsonForScript(personalSubscription)} window.recomendedCurrency = "#{personalSubscription.recurly.currency}" div(ng-controller="RecurlySubscriptionController") diff --git a/services/web/app/views/subscriptions/new.pug b/services/web/app/views/subscriptions/new.pug index c57b6ab474..76df5aa03c 100644 --- a/services/web/app/views/subscriptions/new.pug +++ b/services/web/app/views/subscriptions/new.pug @@ -5,8 +5,8 @@ block scripts window.countryCode = '#{countryCode}' window.plan_code = '#{plan_code}' window.recurlyApiKey = "!{settings.apis.recurly.publicKey}" - window.couponCode = !{JSON.stringify(couponCode)} - window.recomendedCurrency = !{JSON.stringify(currency.slice(0,3))} + window.couponCode = !{StringHelper.stringifyJsonForScript(couponCode)} + window.recomendedCurrency = !{StringHelper.stringifyJsonForScript(currency.slice(0,3))} block content .content.content-alt diff --git a/services/web/app/views/subscriptions/plans.pug b/services/web/app/views/subscriptions/plans.pug index cb845c3d2e..296126265e 100644 --- a/services/web/app/views/subscriptions/plans.pug +++ b/services/web/app/views/subscriptions/plans.pug @@ -10,7 +10,7 @@ block scripts script(type='text/javascript'). window.recomendedCurrency = '#{recomendedCurrency}'; window.abCurrencyFlag = '#{abCurrencyFlag}'; - window.groupPlans = !{JSON.stringify(groupPlans)}; + window.groupPlans = !{StringHelper.stringifyJsonForScript(groupPlans)}; block content .content.content-alt.content-page diff --git a/services/web/app/views/user/activate.pug b/services/web/app/views/user/activate.pug index 8b60b10471..9a77f759d6 100644 --- a/services/web/app/views/user/activate.pug +++ b/services/web/app/views/user/activate.pug @@ -61,4 +61,4 @@ block content span(ng-show="activationForm.inflight") #{translate("activating")}... script(type='text/javascript'). - window.passwordStrengthOptions = !{JSON.stringify(settings.passwordStrengthOptions || {})} + window.passwordStrengthOptions = !{StringHelper.stringifyJsonForScript(settings.passwordStrengthOptions || {})} diff --git a/services/web/app/views/user/sessions.pug b/services/web/app/views/user/sessions.pug index c952daea03..1a462c4642 100644 --- a/services/web/app/views/user/sessions.pug +++ b/services/web/app/views/user/sessions.pug @@ -3,7 +3,7 @@ extends ../layout block scripts script(type='text/javascript'). - window.otherSessions = !{JSON.stringify(sessions)} + window.otherSessions = !{StringHelper.stringifyJsonForScript(sessions)} block content diff --git a/services/web/app/views/user/setPassword.pug b/services/web/app/views/user/setPassword.pug index d983f20049..26a01f8152 100644 --- a/services/web/app/views/user/setPassword.pug +++ b/services/web/app/views/user/setPassword.pug @@ -60,4 +60,4 @@ block content script(type='text/javascript'). window.usersEmail = "#{getReqQueryParam('email')}" - window.passwordStrengthOptions = !{JSON.stringify(settings.passwordStrengthOptions || {})} + window.passwordStrengthOptions = !{StringHelper.stringifyJsonForScript(settings.passwordStrengthOptions || {})} diff --git a/services/web/app/views/user/settings.pug b/services/web/app/views/user/settings.pug index 12af2160cc..d75549f2cb 100644 --- a/services/web/app/views/user/settings.pug +++ b/services/web/app/views/user/settings.pug @@ -292,4 +292,4 @@ block content span(ng-show="state.inflight") #{translate("deleting")}... script(type='text/javascript'). - window.passwordStrengthOptions = !{JSON.stringify(settings.passwordStrengthOptions || {})} + window.passwordStrengthOptions = !{StringHelper.stringifyJsonForScript(settings.passwordStrengthOptions || {})} diff --git a/services/web/app/views/user_membership/index.pug b/services/web/app/views/user_membership/index.pug index 944e7cea97..5a4a726b40 100644 --- a/services/web/app/views/user_membership/index.pug +++ b/services/web/app/views/user_membership/index.pug @@ -103,6 +103,6 @@ block content script(type="text/javascript"). - window.users = !{JSON.stringify(users)}; - window.paths = !{JSON.stringify(paths)}; + window.users = !{StringHelper.stringifyJsonForScript(users)}; + window.paths = !{StringHelper.stringifyJsonForScript(paths)}; window.groupSize = #{groupSize || 'null'};