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

HTML sanitizer for descriptions. #2785

Merged
merged 32 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2881e35
HTML sanitizer for descriptions.
Feb 16, 2020
b79173f
Schema update.
Feb 16, 2020
6b56c15
'description_html' can be modified.
Feb 17, 2020
414ddd5
Attempt for a javascript-side sanitization. Based on DOMPurifier.
May 18, 2020
e1025a9
Document all ToggleButton parameters.
Jun 7, 2020
6a58fd5
Using sanitize-html.
Jun 7, 2020
05b4079
TS compiling.
Jun 7, 2020
e97263b
Adding a plaintext sanitizer (ie tags stripper).
Jun 7, 2020
689d2c0
Schema update.
Jun 7, 2020
17451ec
Merge branch 'master' into HTMLSanitizer
Jun 7, 2020
7a03bb4
Putting things in the right place.
Jun 8, 2020
fc0abfd
Dependency fix.
Jun 8, 2020
99655c3
Test fix.
Jun 8, 2020
58c1a58
Adding <span>.
Jun 8, 2020
b64213a
Test notebook.
Jun 8, 2020
5514bb9
Adding 'style' attribute.
Jun 8, 2020
4b84b90
Little more styling.
Jun 8, 2020
7646c54
No HTML is possible inside the tag '<button>'.
Jun 8, 2020
2e8c38c
s/description_html/description_allow_html
Jun 8, 2020
7f296f0
This almost works, but does not help to get a proper display for desc…
Jun 15, 2020
85382cd
Question of length.
Jun 15, 2020
1056286
Testing with Mathjax.
Jun 15, 2020
dd5ef1f
Syntax correctness for lint.
Jun 15, 2020
f28b5fc
Using LaTeX functions copied from Jupyterlab.
Jul 1, 2020
3945f22
s/let/const.
Jul 1, 2020
a6da1ad
Change plain text to just use textContent directly.
jasongrout Jul 10, 2021
d65b7c2
Merge remote-tracking branch 'origin/master' into HTMLSanitizer
jasongrout Jul 10, 2021
32665c4
Remove style tags during description sanitization
jasongrout Jul 10, 2021
be8adc4
Merge commit '280302e3cfc5262d805d658c910969fe0db50606' into HTMLSani…
jasongrout Jul 10, 2021
9a235d1
Lint
jasongrout Jul 10, 2021
7762fb7
Fix spec for new date and time pickers.
jasongrout Jul 10, 2021
df33205
Merge branch 'master' into HTMLSanitizer
jasongrout Jul 13, 2021
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
22 changes: 11 additions & 11 deletions examples/web1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var WidgetManager = require('./manager').WidgetManager;

require('@jupyter-widgets/controls/css/widgets.css');

document.addEventListener('DOMContentLoaded', function(event) {
document.addEventListener('DOMContentLoaded', function (event) {
var manager = new WidgetManager(document.body);

/**
Expand All @@ -16,20 +16,20 @@ document.addEventListener('DOMContentLoaded', function(event) {
.new_model({
model_module: '@jupyter-widgets/controls',
model_name: widgetType + 'Model',
model_id: 'widget-1'
model_id: 'widget-1',
// Create a view for the model.
})
.then(function(model) {
.then(function (model) {
console.log(widgetType + ' model created');

model.set({
description: description || '',
value: value
value: value,
});

return manager.create_view(model);
}, console.error.bind(console))
.then(function(view) {
.then(function (view) {
console.log(widgetType + ' view created');
manager.display_view(view);
return view;
Expand All @@ -48,26 +48,26 @@ document.addEventListener('DOMContentLoaded', function(event) {
model_id: 'widget-2',
state: {
source: null,
target: null
}
target: null,
},
// Set the link model state.
})
.then(function(link) {
.then(function (link) {
console.log('link created');

return Promise.all([textArea, html]).then(function(models) {
return Promise.all([textArea, html]).then(function (models) {
console.log('setting link');
var textArea = models[0];
var html = models[1];
link.set({
source: [textArea.model, 'value'],
target: [html.model, 'value']
target: [html.model, 'value'],
});
link.save_changes();
console.log('link set');
});
})
.then(function() {
.then(function () {
var event = new Event('widgetsRendered');
document.dispatchEvent(event);
});
Expand Down
8 changes: 4 additions & 4 deletions examples/web1/karma.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Karma configuration
// Generated on Mon Dec 07 2015 08:28:33 GMT-0800 (PST)

module.exports = function(config) {
module.exports = function (config) {
var cfg = {
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
Expand Down Expand Up @@ -42,8 +42,8 @@ module.exports = function(config) {
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
flags: ['--no-sandbox'],
},
},

// Continuous Integration mode
Expand All @@ -52,7 +52,7 @@ module.exports = function(config) {

// Concurrency level
// how many browser should be started simultanous
concurrency: Infinity
concurrency: Infinity,
};

if (process.env.TRAVIS) {
Expand Down
10 changes: 5 additions & 5 deletions examples/web1/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ class WidgetManager extends ManagerBase {
}

loadClass(className, moduleName, moduleVersion) {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
if (moduleName === '@jupyter-widgets/controls') {
resolve(controls);
} else if (moduleName === '@jupyter-widgets/base') {
resolve(base);
} else {
var fallback = function(err) {
var fallback = function (err) {
let failedId = err.requireModules && err.requireModules[0];
if (failedId) {
console.log(
`Falling back to jsDelivr for ${moduleName}@${moduleVersion}`
);
window.require(
[
`https://cdn.jsdelivr.net/npm/${moduleName}@${moduleVersion}/dist/index.js`
`https://cdn.jsdelivr.net/npm/${moduleName}@${moduleVersion}/dist/index.js`,
],
resolve,
reject
Expand All @@ -35,7 +35,7 @@ class WidgetManager extends ManagerBase {
};
window.require([`${moduleName}.js`], resolve, fallback);
}
}).then(function(module) {
}).then(function (module) {
if (module[className]) {
return module[className];
} else {
Expand All @@ -48,7 +48,7 @@ class WidgetManager extends ManagerBase {

display_view(view) {
var that = this;
return Promise.resolve(view).then(view => {
return Promise.resolve(view).then((view) => {
LuminoWidget.attach(view.luminoWidget, that.el);
return view;
});
Expand Down
2 changes: 1 addition & 1 deletion examples/web1/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const widgetsRendered = new Promise((resolve, reject) => {
document.addEventListener('widgetsRendered', listener);
});

describe('index.html', function() {
describe('index.html', function () {
this.timeout(10000);

beforeEach(() => {
Expand Down
12 changes: 6 additions & 6 deletions examples/web1/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ module.exports = {
output: {
filename: 'index.built.js',
path: path.resolve(__dirname, 'built'),
publicPath: 'built/'
publicPath: 'built/',
},
module: {
rules: [
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
// jquery-ui loads some images
{ test: /\.(jpg|png|gif)$/, use: 'file-loader' }
]
{ test: /\.(jpg|png|gif)$/, use: 'file-loader' },
],
},
plugins: [
new webpack.DefinePlugin({
// Needed for Blueprint. See https://github.com/palantir/blueprint/issues/4393
'process.env': '{}',
// Needed for various packages using cwd(), like the path polyfill
process: { cwd: () => '/' }
})
]
process: { cwd: () => '/' },
}),
],
};
10 changes: 5 additions & 5 deletions examples/web2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var WidgetManager = require('./manager').WidgetManager;
require('@jupyter-widgets/controls/css/widgets.css');
require('font-awesome/css/font-awesome.css');

document.addEventListener('DOMContentLoaded', function(event) {
document.addEventListener('DOMContentLoaded', function (event) {
var code = require('./widget_code.py').default;
var inputarea = document.getElementsByClassName('inputarea')[0];
new CodeMirror(inputarea, {
Expand All @@ -15,20 +15,20 @@ document.addEventListener('DOMContentLoaded', function(event) {
tabSize: 4,
showCursorWhenSelecting: true,
viewportMargin: Infinity,
readOnly: true
readOnly: true,
});

var state = require('./widget_state.json');
var widgetarea = document.getElementsByClassName('widgetarea')[0];
var manager = new WidgetManager(widgetarea);
manager
.set_state(state)
.then(models =>
.then((models) =>
manager.create_view(
models.find(
element => element.model_id == '8621699ecc804983a612f09b7dfe806b'
(element) => element.model_id == '8621699ecc804983a612f09b7dfe806b'
)
)
)
.then(view => manager.display_view(view));
.then((view) => manager.display_view(view));
});
10 changes: 5 additions & 5 deletions examples/web2/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ class WidgetManager extends ManagerBase {
}

loadClass(className, moduleName, moduleVersion) {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
if (moduleName === '@jupyter-widgets/controls') {
resolve(controls);
} else if (moduleName === '@jupyter-widgets/base') {
resolve(base);
} else {
var fallback = function(err) {
var fallback = function (err) {
let failedId = err.requireModules && err.requireModules[0];
if (failedId) {
console.log(
`Falling back to jsDelivr for ${moduleName}@${moduleVersion}`
);
window.require(
[
`https://cdn.jsdelivr.net/npm/${moduleName}@${moduleVersion}/dist/index.js`
`https://cdn.jsdelivr.net/npm/${moduleName}@${moduleVersion}/dist/index.js`,
],
resolve,
reject
Expand All @@ -35,7 +35,7 @@ class WidgetManager extends ManagerBase {
};
window.require([`${moduleName}.js`], resolve, fallback);
}
}).then(function(module) {
}).then(function (module) {
if (module[className]) {
return module[className];
} else {
Expand All @@ -48,7 +48,7 @@ class WidgetManager extends ManagerBase {

display_view(view) {
var that = this;
return Promise.resolve(view).then(function(view) {
return Promise.resolve(view).then(function (view) {
LuminoWidget.attach(view.luminoWidget, that.el);
return view;
});
Expand Down
36 changes: 18 additions & 18 deletions examples/web2/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
output: {
filename: 'index.built.js',
path: path.resolve(__dirname, 'built'),
publicPath: 'built/'
publicPath: 'built/',
},
module: {
rules: [
Expand All @@ -22,29 +22,29 @@ module.exports = {
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-woff'
}
}
mimetype: 'application/font-woff',
},
},
},
{
test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-woff'
}
}
mimetype: 'application/font-woff',
},
},
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/octet-stream'
}
}
mimetype: 'application/octet-stream',
},
},
},
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, use: 'file-loader' },
{
Expand All @@ -53,18 +53,18 @@ module.exports = {
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'image/svg+xml'
}
}
}
]
mimetype: 'image/svg+xml',
},
},
},
],
},
plugins: [
new webpack.DefinePlugin({
// Needed for Blueprint. See https://github.com/palantir/blueprint/issues/4393
'process.env': '{}',
// Needed for various packages using cwd(), like the path polyfill
process: { cwd: () => '/' }
})
]
process: { cwd: () => '/' },
}),
],
};
14 changes: 5 additions & 9 deletions examples/web3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@ import { WidgetManager } from './manager';
import {
KernelManager,
ServerConnection,
KernelMessage
KernelMessage,
} from '@jupyterlab/services';

const BASEURL = prompt('Notebook BASEURL', 'http://localhost:8888');
if (BASEURL === null) {
alert('A base URL is needed to run the example!');
throw new Error('A base URL is needed to run the example!');
}
const WSURL =
'ws:' +
BASEURL.split(':')
.slice(1)
.join(':');
const WSURL = 'ws:' + BASEURL.split(':').slice(1).join(':');

document.addEventListener('DOMContentLoaded', async function(event) {
document.addEventListener('DOMContentLoaded', async function (event) {
// Connect to the notebook webserver.
const connectionInfo = ServerConnection.makeSettings({
baseUrl: BASEURL!,
wsUrl: WSURL
wsUrl: WSURL,
});
const kernelManager = new KernelManager({ serverSettings: connectionInfo });
const kernel = await kernelManager.startNew();
Expand All @@ -41,7 +37,7 @@ document.addEventListener('DOMContentLoaded', async function(event) {
tabSize: 4,
showCursorWhenSelecting: true,
viewportMargin: Infinity,
readOnly: true
readOnly: true,
});

// Create the widget area and widget manager
Expand Down
2 changes: 1 addition & 1 deletion examples/web3/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class WidgetManager extends HTMLManager {
_get_comm_info(): Promise<any> {
return this.kernel
.requestCommInfo({ target_name: this.comm_target_name })
.then(reply => (reply.content as any).comms);
.then((reply) => (reply.content as any).comms);
}

kernel: Kernel.IKernelConnection;
Expand Down
Loading