![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/lib/gems/2.5.0/gems/escape_utils-1.0.1/test/javascript/ |
Upload File : |
require File.expand_path("../../helper", __FILE__) class JavascriptEscapeTest < Minitest::Test def test_returns_empty_string_if_nil_passed assert_equal "", EscapeUtils.escape_javascript(nil) end def test_quotes_and_newlines assert_equal %(This \\"thing\\" is really\\n netos\\n\\n\\'), EscapeUtils.escape_javascript(%(This "thing" is really\n netos\r\n\n')) end def test_backslashes assert_equal %(backslash\\\\test), EscapeUtils.escape_javascript(%(backslash\\test)) end def test_closed_html_tags assert_equal %(keep <open>, but dont <\\/close> tags), EscapeUtils.escape_javascript(%(keep <open>, but dont </close> tags)) end if RUBY_VERSION =~ /^1.9/ def test_input_must_be_utf8_or_ascii str = "dont </close> tags" str.force_encoding 'ISO-8859-1' assert_raises Encoding::CompatibilityError do EscapeUtils.escape_javascript(str) end str.force_encoding 'UTF-8' begin EscapeUtils.escape_javascript(str) rescue Encoding::CompatibilityError => e assert_nil e, "#{e.class.name} raised, expected not to" end end def test_return_value_is_tagged_as_utf8 str = "dont </close> tags" assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_javascript(str).encoding end end end