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

Create critical notices conditionals #1633

Merged
merged 1 commit into from
Jul 1, 2019
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
103 changes: 64 additions & 39 deletions libs/modelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ var parseScript = function (aScript) {

var updateURL = null;
var updateUtf = null;
var updateURLForceCheck = process.env.FORCE_BUSY_UPDATEURL_CHECK === 'true';

var downloadURL = null;
var downloadUtf = null;
var rAnyLocalScriptUrl = new RegExp(
Expand Down Expand Up @@ -442,50 +444,73 @@ var parseScript = function (aScript) {
}

// Update Url
if (process.env.FORCE_BUSY_UPDATEURL_CHECK === 'true') {
// `@updateURL` must be exact here for OUJS hosted checks
// e.g. no `search`, no `hash`

updateURL = findMeta(script.meta, 'UserScript.updateURL.0.value');
if (updateURL) {
// Check for decoding error
try {
updateUtf = decodeURIComponent(updateURL);

} catch (aE) {
script.hasInvalidUpdateURL = true;
script.showSourceNotices = true;

} finally {
if (!script.hasInvalidUpdateURL) {

// Validate `author` and `name` (installNameBase) to this scripts meta only
matches = updateUtf.match(rAnyLocalMetaUrl);
if (matches) {
if (script.authorSlug.toLowerCase() + '/' + script.nameSlug === matches[1].toLowerCase() + '/' + matches[2])
{
// Same script
} else {
script.hasInvalidUpdateURL = true;
script.showSourceNotices = true;
}
// `@updateURL` must be exact here for OUJS hosted checks with updateURLForceCheck
// e.g. no `search`, no `hash`

updateURL = findMeta(script.meta, 'UserScript.updateURL.0.value');
if (updateURL) {
// Check for decoding error
try {
updateUtf = decodeURIComponent(updateURL);

} catch (aE) {
script.hasAlternateUpdateURL = true;
script.hasInvalidUpdateURL = true;

script.showSourceNotices = true;
script.showSourceNoticesCritical = true;
} finally {
if (!script.hasInvalidUpdateURL) {
// Validate `author` and `name` (installNameBase) to this scripts meta only
matches = updateUtf.match(rAnyLocalMetaUrl);
if (matches) {
if (script.authorSlug.toLowerCase() + '/' + script.nameSlug ===
matches[1].toLowerCase() + '/' + matches[2])
{
// Same meta
} else {
// Allow offsite checks
updateURL = new URL(updateURL);
if (rSameOrigin.test(updateURL.origin)) {
script.hasInvalidUpdateURL = true;
script.showSourceNotices = true;
script.hasAlternateUpdateURL = true;
script.hasInvalidUpdateURL = (
updateURLForceCheck
? updateURLForceCheck
: script.hasInvalidUpdateURL
);

}
script.showSourceNotices = true;
script.showSourceNoticesCritical = updateURLForceCheck;
}
} else {
// Allow offsite checks
updateURL = new URL(updateURL);
if (rSameOrigin.test(updateURL.origin)) {
script.hasAlternateUpdateURL = true;
script.hasInvalidUpdateURL = (
updateURLForceCheck
? updateURLForceCheck
: script.hasInvalidUpdateURL
);

script.showSourceNotices = true;
script.showSourceNoticesCritical = true;
} else {
script.hasAlternateUpdateURL = true;

script.showSourceNotices = true;
}
}
}
} else {
if (!script.isLib) {
// Don't serve the script anywhere in this mode and if absent
script.hasInvalidUpdateURL = true;
script.showSourceNotices = true;
}
}
} else {
if (!script.isLib) {
// If updateURLForceCheck is true don't serve the script anywhere in this mode and if absent
script.hasInvalidUpdateURL = (
updateURLForceCheck
? updateURLForceCheck
: script.hasInvalidUpdateURL
);

script.showSourceNotices = updateURLForceCheck;
script.showSourceNoticesCritical = updateURLForceCheck;
}
}

Expand Down
1 change: 1 addition & 0 deletions views/includes/scriptList.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<tr class="tr-link">
<td>
{{#showSourceNotices}}<span class="pull-right"><i class="fa fa-fw fa-exclamation-triangle" title="Source Code notices"></i></span>{{/showSourceNotices}}
{{#showSourceNoticesCritical}}<span class="pull-right"><i class="fa fa-fw fa-exclamation-circle" title="Critical Source Code notices"></i></span>{{/showSourceNoticesCritical}}
{{#_issueCount}}<span class="pull-right"><a href="{{{scriptIssuesPageUri}}}/open" title="Open issue discussions"><i class="fa fa-fw fa-commenting"></i>{{_issueCount}}</a></span>{{/_issueCount}}
<span class="script-icon hidden-xs" {{#icon16Url}}data-icon-src="{{{icon16Url}}}" data-icon-size="16"{{/icon16Url}}>
{{#isLib}}<i class="fa fa-fw fa-file-excel-o"></i>{{/isLib}}{{^isLib}}<i class="fa fa-fw fa-file-code-o"></i>{{/isLib}}
Expand Down
12 changes: 6 additions & 6 deletions views/includes/scriptPageHeader.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ <h2 class="page-heading">
{{#isScriptPage}}
{{^script.isLib}}
<div class="btn-group pull-right">
<a href="{{{script.scriptInstallPageUrl}}}" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}warning{{/script.showSourceNotices}}">
<a href="{{{script.scriptInstallPageUrl}}}" class="btn btn-{{^script.showSourceNoticesCritical}}info{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}">
<i class="fa fa-download"></i> Install
</a>
<button type="button" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}warning{{/script.showSourceNotices}} dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<button type="button" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}{{^script.showSourceNoticesCritical}}warning{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}{{/script.showSourceNotices}} dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li>
<div class="btn-group btn-group-justified">
<a href="{{{script.scriptInstallPageXUrl}}}.min.user.js" class="btn btn-{{#script.showSourceNotices}}warning{{/script.showSourceNotices}}{{^script.showSourceNotices}}info{{/script.showSourceNotices}}" title="EXPERIMENTAL INSTALLATION FORKING"><i class="fa fa-fw fa-download"></i> Install {{#script.hasAlternateDownloadURL}}once {{/script.hasAlternateDownloadURL}} with minification</a>
<a href="{{{script.scriptInstallPageXUrl}}}.min.user.js" class="btn btn-{{#script.showSourceNotices}}{{^script.showSourceNoticesCritical}}warning{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}{{/script.showSourceNotices}}{{^script.showSourceNotices}}info{{/script.showSourceNotices}}" title="EXPERIMENTAL INSTALLATION FORKING"><i class="fa fa-fw fa-download"></i> Install {{#script.hasAlternateDownloadURL}}once {{/script.hasAlternateDownloadURL}} with minification</a>
</div>
{{#script.showSourceNotices}}
{{> includes/scriptPageHeaderSourceNotices.html }}
Expand All @@ -26,17 +26,17 @@ <h2 class="page-heading">
{{/isScriptPage}}
{{#isScriptViewSourcePage}}
<div class="btn-group pull-right">
<a href="{{{script.scriptRawPageUrl}}}" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}warning{{/script.showSourceNotices}}">
<a href="{{{script.scriptRawPageUrl}}}" class="btn btn-{{^script.showSourceNoticesCritical}}info{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}">
<i class="fa fa-file-{{#script.isLib}}excel{{/script.isLib}}{{^script.isLib}}code{{/script.isLib}}-o"></i> Raw Source
</a>
<button type="button" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}warning{{/script.showSourceNotices}} dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<button type="button" class="btn btn-{{^script.showSourceNotices}}info{{/script.showSourceNotices}}{{#script.showSourceNotices}}{{^script.showSourceNoticesCritical}}warning{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}{{/script.showSourceNotices}} dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li>
<div class="btn-group btn-group-justified">
<a href="{{{script.scriptRawPageXUrl}}}" class="btn btn-{{#script.showSourceNotices}}warning{{/script.showSourceNotices}}{{^script.showSourceNotices}}info{{/script.showSourceNotices}}" title="EXPERIMENTAL"><i class="fa fa-file-{{#script.isLib}}excel{{/script.isLib}}{{^script.isLib}}code{{/script.isLib}}-o"></i> Minified Source</a>
<a href="{{{script.scriptRawPageXUrl}}}" class="btn btn-{{#script.showSourceNotices}}{{^script.showSourceNoticesCritical}}warning{{/script.showSourceNoticesCritical}}{{#script.showSourceNoticesCritical}}danger{{/script.showSourceNoticesCritical}}{{/script.showSourceNotices}}{{^script.showSourceNotices}}info{{/script.showSourceNotices}}" title="EXPERIMENTAL"><i class="fa fa-file-{{#script.isLib}}excel{{/script.isLib}}{{^script.isLib}}code{{/script.isLib}}-o"></i> Minified Source</a>
</div>
{{#script.showSourceNotices}}
{{> includes/scriptPageHeaderSourceNotices.html }}
Expand Down
19 changes: 12 additions & 7 deletions views/includes/scriptPageHeaderSourceNotices.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
<div class="alert alert-warning" role="alert">
{{#script.hasInvalidUpdateURL}}
<p>
<i class="fa fa-fw fa-exclamation-triangle"></i> Invalid update target
<i class="fa fa-fw fa-exclamation-circle"></i> Invalid update target.
</p>
{{/script.hasInvalidUpdateURL}}
{{#script.hasAlternateUpdateURL}}
<p{{^isScriptViewSourcePage}} title="{{script.meta.UserScript.updateURL.0.value}}"{{/isScriptViewSourcePage}}>
<i class="fa fa-fw fa-exclamation-triangle"></i> Alternate update target.
</p>
{{/script.hasAlternateUpdateURL}}
{{#script.hasInvalidDownloadURL}}
<p>
<i class="fa fa-fw fa-exclamation-triangle"></i> Invalid download target
<i class="fa fa-fw fa-exclamation-circle"></i> Invalid download target.
</p>
{{/script.hasInvalidDownloadURL}}
{{#script.hasUnstableMinify}}
<p{{^isScriptViewSourcePage}} title="{{script.meta.OpenUserJS.unstableMinify.0.value}}"{{/isScriptViewSourcePage}}>
<i class="fa fa-fw fa-exclamation-triangle"></i> The script author suggests that minification of this script may be unstable.
<p>
{{/script.hasUnstableMinify}}
{{#script.hasAlternateDownloadURL}}
<p{{^isScriptViewSourcePage}} title="{{script.meta.UserScript.downloadURL.0.value}}"{{/isScriptViewSourcePage}}>
<i class="fa fa-fw fa-exclamation-triangle"></i> Alternate download target.
</p>
{{/script.hasAlternateDownloadURL}}
{{#script.hasUnstableMinify}}
<p{{^isScriptViewSourcePage}} title="{{script.meta.OpenUserJS.unstableMinify.0.value}}"{{/isScriptViewSourcePage}}>
<i class="fa fa-fw fa-exclamation-triangle"></i> The script author suggests that minification of this script may be unstable.
<p>
{{/script.hasUnstableMinify}}
</div>