Website : rimsha.abasa.com
backdoor
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
canvas
/
node_modules
/
@canvas
/
package-tests
/
__tests__
/
Filename :
htmlEscape.test.js
back
Copy
/* * Copyright (C) 2018 - present Instructure, Inc. * * This file is part of Canvas. * * Canvas is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the Free * Software Foundation, version 3 of the License. * * Canvas 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 Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License along * with this program. If not, see <http://www.gnu.org/licenses/>. */ import $ from 'jquery' import htmlEscape, {unescape} from '@instructure/html-escape' const equal = (a, b) => expect(a).toBe(b) const strictEqual = (a, b) => expect(a).toBe(b) describe('htmlEscape', () => { describe('.htmlEscape()', () => { test('replaces "&" with "&"', () => { equal(htmlEscape('foo & bar'), 'foo & bar') }) test('replaces "<" with "<"', () => { equal(htmlEscape('foo < bar'), 'foo < bar') }) test('replaces ">" with ">"', () => { equal(htmlEscape('foo > bar'), 'foo > bar') }) test('replaces " with """', () => { equal(htmlEscape('foo " bar'), 'foo " bar') }) test('replaces \' with "'"', () => { equal(htmlEscape("foo ' bar"), 'foo ' bar') }) test('replaces "/" with "/"', () => { equal(htmlEscape('foo / bar'), 'foo / bar') }) test('replaces "`" with "`"', () => { equal(htmlEscape('foo ` bar'), 'foo ` bar') }) test('replaces "=" with "="', () => { equal(htmlEscape('foo = bar'), 'foo = bar') }) test('replaces any combination of known replaceable values', () => { const value = '& < > " \' / ` =' equal(htmlEscape(value), '& < > " ' / ` =') }) test('htmlEscape with jQuery object', function () { const $regradeInfoSpan = $('<span id="regrade_info_span">This is a test</span>') // attempt to escape jQuery object, this should be a no-op const result = htmlEscape($regradeInfoSpan) strictEqual( result, $regradeInfoSpan, `Passing a jQuery object should return ${$regradeInfoSpan}` ) }) }) describe('.unescape()', () => { test('replaces "&" with "&"', () => { equal(unescape('foo & bar'), 'foo & bar') }) test('replaces "<" with "<"', () => { equal(unescape('foo < bar'), 'foo < bar') }) test('replaces ">" with ">"', () => { equal(unescape('foo > bar'), 'foo > bar') }) test('replaces """ with "', () => { equal(unescape('foo " bar'), 'foo " bar') }) test('replaces "'" with \'', () => { equal(unescape('foo ' bar'), "foo ' bar") }) test('replaces "/" with "/"', () => { equal(unescape('foo / bar'), 'foo / bar') }) test('replaces "`" with "`"', () => { equal(unescape('foo ` bar'), 'foo ` bar') }) test('replaces "=" with "="', () => { equal(unescape('foo = bar'), 'foo = bar') }) test('replaces any combination of known replaceable values', () => { const value = '& < > " ' / ` =' equal(unescape(value), '& < > " \' / ` =') }) }) })