forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescJs.php
More file actions
48 lines (41 loc) · 1.28 KB
/
escJs.php
File metadata and controls
48 lines (41 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* @group formatting
*
* @covers ::esc_js
*/
class Tests_Formatting_EscJs extends WP_UnitTestCase {
public function test_js_escape_simple() {
$out = esc_js( 'foo bar baz();' );
$this->assertSame( 'foo bar baz();', $out );
}
public function test_js_escape_quotes() {
$out = esc_js( 'foo "bar" \'baz\'' );
// Does it make any sense to change " into "? Why not \"?
$this->assertSame( "foo "bar" \'baz\'", $out );
}
public function test_js_escape_backslash() {
$bs = '\\';
$out = esc_js( 'foo ' . $bs . 't bar ' . $bs . $bs . ' baz' );
// \t becomes t - bug?
$this->assertSame( 'foo t bar ' . $bs . $bs . ' baz', $out );
}
public function test_js_escape_amp() {
$out = esc_js( 'foo & bar &baz; ' );
$this->assertSame( 'foo & bar &baz; ', $out );
}
public function test_js_escape_quote_entity() {
$out = esc_js( 'foo ' bar ' baz &' );
$this->assertSame( "foo \\' bar \\' baz &", $out );
}
public function test_js_no_carriage_return() {
$out = esc_js( "foo\rbar\nbaz\r" );
// \r is stripped.
$this->assertSame( "foobar\\nbaz", $out );
}
public function test_js_escape_rn() {
$out = esc_js( "foo\r\nbar\nbaz\r\n" );
// \r is stripped.
$this->assertSame( "foo\\nbar\\nbaz\\n", $out );
}
}