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

Commit 7d3a3a6

Browse files
authored
Merge pull request #47 from shinsenter/develop
Bug fixes
2 parents d6ad921 + b16d7dc commit 7d3a3a6

File tree

7 files changed

+93
-55
lines changed

7 files changed

+93
-55
lines changed

assets/helpers.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
(function (window, document, console, name) {
3636

37-
var PROJECT_URL = 'https://github.com/shinsenter/';
37+
var PROJECT_URL = ' https://github.com/shinsenter/';
3838
var PROJECT_NAME = 'defer.js';
3939
var CLASS_PREFIX = 'defer-';
4040
var CLASS_SUFFIX = 'deferjs';
@@ -90,9 +90,9 @@
9090

9191
log([
9292
'Optimized by ' + PROJECT_NAME,
93-
'(c) 2019 Mai Nhut Tan <[email protected]>',
94-
'Github: ' + PROJECT_URL + PROJECT_NAME,
95-
'PHP lib: ' + PROJECT_URL + 'defer.php'
93+
'(c) 2019 Mai Nhut Tan',
94+
'Github: ' + PROJECT_URL + PROJECT_NAME,
95+
'PHP lib:' + PROJECT_URL + 'defer.php'
9696
].join('\n'));
9797
}
9898

@@ -223,6 +223,6 @@
223223
window[ADD_EVENT_LISTENER](LOAD_EVENT, deferscript);
224224

225225
defermedia();
226-
copyright();
226+
// copyright();
227227

228228
})(this, document, console, 'defer_helper');

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"name": "Mai Nhut Tan",
4545
"email": "[email protected]",
4646
"homepage": "https://code.shin.company",
47-
"role": "Developer"
47+
"role": "Owner"
4848
}
4949
],
5050
"scripts":

composer.lock

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/helpers.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Defer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ public function clearCache()
208208
protected function nodefer()
209209
{
210210
$no_libxml = !$this->native_libxml;
211-
$has_nodefer = (bool) $this->http->request()->get($this->no_defer_parameter);
211+
$request = $this->http->request();
212+
$has_nodefer = $request ? (bool) $request->get($this->no_defer_parameter) : false;
212213

213214
return $has_nodefer || $no_libxml;
214215
}
@@ -239,6 +240,6 @@ protected function debugTags()
239240
$output[] = $this->dom->saveHtml($node);
240241
}
241242

242-
return implode("\n", $output);
243+
return implode("\n", array_unique($output));
243244
}
244245
}

src/DeferParser.php

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -466,25 +466,20 @@ protected function entity2charset($html, $charset)
466466

467467
if ($encoding === false || $encoding === 'ASCII') {
468468
$encoding = 'HTML-ENTITIES';
469+
}
469470

470-
if (is_null(static::$__html_mapping)) {
471-
$mapping = array_values(get_html_translation_table(HTML_SPECIALCHARS));
472-
473-
static::$__html_mapping = [
474-
'from' => $mapping,
475-
'to' => array_map('htmlspecialchars', $mapping),
476-
];
477-
478-
unset($mapping);
479-
}
480-
481-
$html = str_replace(static::$__html_mapping['from'], static::$__html_mapping['to'], $html);
471+
if ($encoding == 'HTML-ENTITIES') {
472+
$html = $this->escapeHtmlEntity($html, false);
482473
}
483474

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

479+
if ($encoding == 'HTML-ENTITIES') {
480+
$html = $this->escapeHtmlEntity($html, true);
481+
}
482+
488483
return $html;
489484
}
490485

@@ -715,4 +710,46 @@ protected function script_decode($html)
715710

716711
return $result;
717712
}
713+
714+
/**
715+
* Escape / unescape regular HTML entities
716+
*
717+
* @since 1.0.17
718+
* @param string $html
719+
* @param bool $revert = false
720+
* @return string
721+
*/
722+
protected function escapeHtmlEntity($html, $revert = false)
723+
{
724+
// Initial HTML entity optimizer
725+
if (is_null(static::$__html_mapping)) {
726+
$mapping = array_values(get_html_translation_table(HTML_SPECIALCHARS));
727+
728+
static::$__html_mapping = [
729+
'from' => $mapping,
730+
'to' => array_map(function ($v) {
731+
return str_replace(['&', ';'], ['@&@', '@;@'], $v);
732+
}, $mapping),
733+
];
734+
735+
unset($mapping);
736+
}
737+
738+
// Process the HTML
739+
if ($revert) {
740+
$html = str_replace(
741+
static::$__html_mapping['to'],
742+
static::$__html_mapping['from'],
743+
$html
744+
);
745+
} else {
746+
$html = str_replace(
747+
static::$__html_mapping['from'],
748+
static::$__html_mapping['to'],
749+
$html
750+
);
751+
}
752+
753+
return $html;
754+
}
718755
}

test/test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
error_reporting(E_ALL);
1515

1616
if (!defined('DEFER_JS_VERSION')) {
17-
define('DEFER_JS_VERSION', '1.1.7-c');
17+
define('DEFER_JS_VERSION', '1.1.10');
1818
}
1919

2020
define('TEST_DS', DIRECTORY_SEPARATOR);

0 commit comments

Comments
 (0)