Skip to content

Commit 4d36b0b

Browse files
authored
Merge pull request #364 from RRosio/npm_google-caja
Migrate google-caja to npm
2 parents 50ce172 + fdd921c commit 4d36b0b

File tree

6 files changed

+92
-103
lines changed

6 files changed

+92
-103
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"watch:css": "onchange 'nbclassic/static/**/*.less' -- npm run build:css",
3535
"watch:js": "onchange 'nbclassic/static/**/!(*.min).js' 'bower.json' -- npm run build:js",
3636
"watch": "npm-run-all --parallel watch:*",
37-
"postinstall": "node postinstall.js"
37+
"postinstall": "node postinstall.js && npx patch-package"
3838
},
3939
"devDependencies": {
4040
"@babel/core": "^7.15.0",
@@ -63,7 +63,7 @@
6363
"mathjax": "^2.7.4",
6464
"codemirror": "~5.58.2",
6565
"es6-promise": "~1.0",
66-
"@bower_components/google-caja": "https://github.com/minrk/google-caja-bower/archive/refs/tags/5669.0.0.tar.gz",
66+
"google-caja-sanitizer": "~1.0.4",
6767
"jed": "~1.1.1",
6868
"jquery": "~3.7.1",
6969
"jquery-typeahead": "~2.11.1",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
diff --git a/node_modules/google-caja-sanitizer/sanitizer.js b/node_modules/google-caja-sanitizer/sanitizer.js
2+
index bf8ff98..43e8173 100644
3+
--- a/node_modules/google-caja-sanitizer/sanitizer.js
4+
+++ b/node_modules/google-caja-sanitizer/sanitizer.js
5+
@@ -4919,16 +4919,16 @@ var html = (function(html4) {
6+
})(html4);
7+
8+
9+
-exports.escapeAttrib = html.escapeAttrib;
10+
-exports.makeHtmlSanitizer = html.makeHtmlSanitizer;
11+
-exports.makeSaxParser = html.makeSaxParser;
12+
-exports.makeTagPolicy = html.makeTagPolicy;
13+
-exports.normalizeRCData = html.normalizeRCData;
14+
-exports.sanitize = html.sanitize;
15+
-exports.smartSanitize = function (string, urlX, idX) {
16+
- string = string.replace(/<([a-zA-Z]+)([^>]*)\/>/g, '<$1$2></$1>');
17+
- return html.sanitize(string, urlX, idX);
18+
-}
19+
-exports.sanitizeAttribs = html.sanitizeAttribs;
20+
-exports.sanitizeWithPolicy = html.sanitizeWithPolicy;
21+
-exports.unescapeEntities = html.unescapeEntities;
22+
+// exports.escapeAttrib = html.escapeAttrib;
23+
+// exports.makeHtmlSanitizer = html.makeHtmlSanitizer;
24+
+// exports.makeSaxParser = html.makeSaxParser;
25+
+// exports.makeTagPolicy = html.makeTagPolicy;
26+
+// exports.normalizeRCData = html.normalizeRCData;
27+
+// exports.sanitize = html.sanitize;
28+
+// exports.smartSanitize = function (string, urlX, idX) {
29+
+// string = string.replace(/<([a-zA-Z]+)([^>]*)\/>/g, '<$1$2></$1>');
30+
+// return html.sanitize(string, urlX, idX);
31+
+// }
32+
+// exports.sanitizeAttribs = html.sanitizeAttribs;
33+
+// exports.sanitizeWithPolicy = html.sanitizeWithPolicy;
34+
+// exports.unescapeEntities = html.unescapeEntities;

postinstall.js

Lines changed: 49 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
const fs = require("fs");
22
const path = require("path");
33

4+
const isWin = process.platform === "win32";
5+
const LINK_TYPE = isWin ? "junction" : "dir";
6+
7+
function ensureDir(p) {
8+
fs.mkdirSync(p, { recursive: true });
9+
}
10+
411
function ensureSymlink(sourcePath, targetPath) {
512
const source = path.resolve(sourcePath);
613
const target = path.resolve(targetPath);
714

15+
ensureDir(path.dirname(target));
16+
17+
if (!fs.existsSync(source)) {
18+
console.warn(`Skipping symlink; source missing: ${source}`);
19+
return false;
20+
}
21+
822
try {
923
const stat = fs.lstatSync(target);
1024
if (!stat.isSymbolicLink()) {
1125
console.log(`Removing non-symlink at: ${target}`);
1226
fs.rmSync(target, { recursive: true, force: true });
1327
} else {
14-
const exists = fs.readlinkSync(target);
15-
if (path.resolve(exists) === source) {
16-
console.log(`Symlink exists at: ${target}`);
17-
return;
18-
}
19-
console.log(`Replacing symlink at: ${target}`);
20-
fs.unlinkSync(target);
28+
const exists = fs.readlinkSync(target);
29+
if (path.resolve(exists) === source) {
30+
console.log(`Symlink exists at: ${target}`);
31+
return;
32+
}
33+
console.log(`Replacing symlink at: ${target}`);
34+
fs.unlinkSync(target);
2135
}
2236
} catch (e) {
2337
if (e.code !== "ENOENT") {
@@ -26,11 +40,7 @@ function ensureSymlink(sourcePath, targetPath) {
2640
}
2741

2842
try {
29-
fs.symlinkSync(
30-
path.resolve(source),
31-
path.resolve(target),
32-
"junction"
33-
);
43+
fs.symlinkSync(source, target, LINK_TYPE);
3444
console.log(`Symlink created: ${sourcePath} -> ${targetPath}`);
3545
} catch (e) {
3646
if (e.code !== "EEXIST") {
@@ -39,87 +49,31 @@ function ensureSymlink(sourcePath, targetPath) {
3949
}
4050
}
4151

42-
// Symlink bower_components
43-
ensureSymlink("node_modules/@bower_components", "nbclassic/static/components");
52+
ensureDir("nbclassic/static/components");
4453

45-
// Symlink other static assets no longer in bower_components
46-
ensureSymlink(
47-
"node_modules/marked",
48-
"nbclassic/static/components/marked"
49-
);
50-
ensureSymlink(
51-
"node_modules/font-awesome",
52-
"nbclassic/static/components/font-awesome"
53-
);
54-
ensureSymlink(
55-
"node_modules/backbone",
56-
"nbclassic/static/components/backbone"
57-
);
58-
ensureSymlink(
59-
"node_modules/bootstrap",
60-
"nbclassic/static/components/bootstrap"
61-
);
62-
ensureSymlink(
63-
"node_modules/bootstrap-tour",
64-
"nbclassic/static/components/bootstrap-tour"
65-
);
66-
ensureSymlink(
67-
"node_modules/jed",
68-
"nbclassic/static/components/jed"
69-
);
70-
ensureSymlink(
71-
"node_modules/moment",
72-
"nbclassic/static/components/moment"
73-
);
74-
ensureSymlink(
75-
"node_modules/text-encoding",
76-
"nbclassic/static/components/text-encoding"
77-
);
78-
ensureSymlink(
79-
"node_modules/underscore",
80-
"nbclassic/static/components/underscore"
81-
);
82-
ensureSymlink(
83-
"node_modules/jquery",
84-
"nbclassic/static/components/jquery"
85-
);
86-
ensureSymlink(
87-
"node_modules/jquery-ui",
88-
"nbclassic/static/components/jquery-ui"
89-
);
90-
ensureSymlink(
91-
"node_modules/jquery-typeahead",
92-
"nbclassic/static/components/jquery-typeahead"
93-
);
94-
ensureSymlink(
95-
"node_modules/mathjax",
96-
"nbclassic/static/components/MathJax"
97-
);
98-
ensureSymlink(
99-
"node_modules/codemirror",
100-
"nbclassic/static/components/codemirror"
101-
);
102-
ensureSymlink(
103-
"node_modules/react",
104-
"nbclassic/static/components/react"
105-
);
106-
ensureSymlink(
107-
"node_modules/react-dom",
108-
"nbclassic/static/components/react-dom"
109-
);
110-
ensureSymlink(
111-
"node_modules/es6-promise",
112-
"nbclassic/static/components/es6-promise"
113-
);
114-
ensureSymlink(
115-
"node_modules/requirejs",
116-
"nbclassic/static/components/requirejs"
117-
);
118-
ensureSymlink(
119-
"node_modules/requirejs-plugins",
120-
"nbclassic/static/components/requirejs-plugins"
121-
);
122-
ensureSymlink(
123-
"node_modules/requirejs-text",
124-
"nbclassic/static/components/requirejs-text"
125-
);
54+
[
55+
"marked",
56+
"font-awesome",
57+
"backbone",
58+
"bootstrap",
59+
"bootstrap-tour",
60+
"jed",
61+
"moment",
62+
"text-encoding",
63+
"underscore",
64+
"jquery",
65+
"jquery-ui",
66+
"jquery-typeahead",
67+
"codemirror",
68+
"react",
69+
"react-dom",
70+
"es6-promise",
71+
"requirejs",
72+
"requirejs-plugins",
73+
"requirejs-text",
74+
"google-caja-sanitizer",
75+
"mathjax",
76+
].forEach((pkg) => {
77+
const dst = pkg === "mathjax" ? "MathJax" : pkg;
78+
ensureSymlink(`node_modules/${pkg}`, `nbclassic/static/components/${dst}`);
79+
});

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ artifacts = [
129129
"nbclassic/static/components/bootstrap-tour/build/js/bootstrap-tour.min.js" = "nbclassic/static/components/bootstrap-tour/build/js/bootstrap-tour.min.js"
130130
"nbclassic/static/components/bootstrap/dist/js/bootstrap.min.js" = "nbclassic/static/components/bootstrap/dist/js/bootstrap.min.js"
131131
"nbclassic/static/components/create-react-class/index.js" = "nbclassic/static/components/create-react-class/index.js"
132-
"nbclassic/static/components/google-caja/html-css-sanitizer-minified.js" = "nbclassic/static/components/google-caja/html-css-sanitizer-minified.js"
132+
"nbclassic/static/components/google-caja-sanitizer/sanitizer.js" = "nbclassic/static/components/google-caja-sanitizer/sanitizer.js"
133133
"nbclassic/static/components/jed/jed.js" = "nbclassic/static/components/jed/jed.js"
134134
"nbclassic/static/components/jquery/dist/jquery.min.js" = "nbclassic/static/components/jquery/dist/jquery.min.js"
135135
"nbclassic/static/components/jquery-typeahead/dist/jquery.typeahead.min.js" = "nbclassic/static/components/jquery-typeahead/dist/jquery.typeahead.min.js"

tools/security_deprecated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
define([
55
'jquery',
6-
'components/google-caja/html-css-sanitizer-minified',
6+
'components/google-caja-sanitizer/sanitizer',
77
], function($, sanitize) {
88
"use strict";
99

yarn.lock

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,6 @@
841841
classnames "^2.2"
842842
tslib "~2.3.1"
843843

844-
"@bower_components/google-caja@https://github.com/minrk/google-caja-bower/archive/refs/tags/5669.0.0.tar.gz":
845-
version "0.0.0"
846-
resolved "https://github.com/minrk/google-caja-bower/archive/refs/tags/5669.0.0.tar.gz#6830582db17ef8087e38d3aa9703966fb9a86278"
847-
848844
"@discoveryjs/json-ext@^0.5.0":
849845
version "0.5.7"
850846
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
@@ -2077,6 +2073,11 @@ globals@^11.1.0:
20772073
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
20782074
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==
20792075

2076+
google-caja-sanitizer@~1.0.4:
2077+
version "1.0.4"
2078+
resolved "https://registry.yarnpkg.com/google-caja-sanitizer/-/google-caja-sanitizer-1.0.4.tgz#614cf2c3d2e5e83ea961ab98d79318c03d8682e5"
2079+
integrity sha512-KEqGmAIbxvEZy4nPLpVoAlxQhEoq4H/0WMEQsEXlxjP+OxCT9nDYQi7Z7PVanwb77Jc+OJ9SoBQ6zw2OnmCvLw==
2080+
20802081
gopd@^1.0.1, gopd@^1.2.0:
20812082
version "1.2.0"
20822083
resolved "https://registry.yarnpkg.com/gopd/-/gopd-1.2.0.tgz#89f56b8217bdbc8802bd299df6d7f1081d7e51a1"

0 commit comments

Comments
 (0)