Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Bug fixes #47

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions assets/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
(function (window, document, console, name) {

var PROJECT_URL = 'https://github.com/shinsenter/';
var PROJECT_URL = ' https://github.com/shinsenter/';
var PROJECT_NAME = 'defer.js';
var CLASS_PREFIX = 'defer-';
var CLASS_SUFFIX = 'deferjs';
Expand Down Expand Up @@ -90,9 +90,9 @@

log([
'Optimized by ' + PROJECT_NAME,
'(c) 2019 Mai Nhut Tan <[email protected]>',
'Github: ' + PROJECT_URL + PROJECT_NAME,
'PHP lib: ' + PROJECT_URL + 'defer.php'
'(c) 2019 Mai Nhut Tan',
'Github: ' + PROJECT_URL + PROJECT_NAME,
'PHP lib:' + PROJECT_URL + 'defer.php'
].join('\n'));
}

Expand Down Expand Up @@ -223,6 +223,6 @@
window[ADD_EVENT_LISTENER](LOAD_EVENT, deferscript);

defermedia();
copyright();
// copyright();

})(this, document, console, 'defer_helper');
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"name": "Mai Nhut Tan",
"email": "[email protected]",
"homepage": "https://code.shin.company",
"role": "Developer"
"role": "Owner"
}
],
"scripts":
Expand Down
66 changes: 33 additions & 33 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/helpers.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/Defer.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public function clearCache()
protected function nodefer()
{
$no_libxml = !$this->native_libxml;
$has_nodefer = (bool) $this->http->request()->get($this->no_defer_parameter);
$request = $this->http->request();
$has_nodefer = $request ? (bool) $request->get($this->no_defer_parameter) : false;

return $has_nodefer || $no_libxml;
}
Expand Down Expand Up @@ -239,6 +240,6 @@ protected function debugTags()
$output[] = $this->dom->saveHtml($node);
}

return implode("\n", $output);
return implode("\n", array_unique($output));
}
}
61 changes: 49 additions & 12 deletions src/DeferParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,25 +466,20 @@ protected function entity2charset($html, $charset)

if ($encoding === false || $encoding === 'ASCII') {
$encoding = 'HTML-ENTITIES';
}

if (is_null(static::$__html_mapping)) {
$mapping = array_values(get_html_translation_table(HTML_SPECIALCHARS));

static::$__html_mapping = [
'from' => $mapping,
'to' => array_map('htmlspecialchars', $mapping),
];

unset($mapping);
}

$html = str_replace(static::$__html_mapping['from'], static::$__html_mapping['to'], $html);
if ($encoding == 'HTML-ENTITIES') {
$html = $this->escapeHtmlEntity($html, false);
}

if ($this->charset !== $encoding) {
$html = mb_convert_encoding($html, $charset, $encoding);
}

if ($encoding == 'HTML-ENTITIES') {
$html = $this->escapeHtmlEntity($html, true);
}

return $html;
}

Expand Down Expand Up @@ -715,4 +710,46 @@ protected function script_decode($html)

return $result;
}

/**
* Escape / unescape regular HTML entities
*
* @since 1.0.17
* @param string $html
* @param bool $revert = false
* @return string
*/
protected function escapeHtmlEntity($html, $revert = false)
{
// Initial HTML entity optimizer
if (is_null(static::$__html_mapping)) {
$mapping = array_values(get_html_translation_table(HTML_SPECIALCHARS));

static::$__html_mapping = [
'from' => $mapping,
'to' => array_map(function ($v) {
return str_replace(['&', ';'], ['@&@', '@;@'], $v);
}, $mapping),
];

unset($mapping);
}

// Process the HTML
if ($revert) {
$html = str_replace(
static::$__html_mapping['to'],
static::$__html_mapping['from'],
$html
);
} else {
$html = str_replace(
static::$__html_mapping['from'],
static::$__html_mapping['to'],
$html
);
}

return $html;
}
}
2 changes: 1 addition & 1 deletion test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
error_reporting(E_ALL);

if (!defined('DEFER_JS_VERSION')) {
define('DEFER_JS_VERSION', '1.1.7-c');
define('DEFER_JS_VERSION', '1.1.10');
}

define('TEST_DS', DIRECTORY_SEPARATOR);
Expand Down