Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: yukinying/connect-strictenjs
base: d6104acf8c
...
head fork: yukinying/connect-strictenjs
compare: e2be2d4223
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
0  examples/html/favicon.ico
No changes.
View
19 examples/html/global.html
@@ -0,0 +1,19 @@
+<html>
+
+<div id='test'>
+<script>
+
+console.log(this);
+(function(){
+
+ console.log('call global variable directly');
+ console.log(window.addEventListener);
+
+ var j = this;
+ console.log('call this and in hope that it is the global variable');
+ console.log(this.addEventListener);
+
+})();
+</script>
+</div>
+</html>
View
2  examples/static.js
@@ -15,4 +15,4 @@ app.use(strict.beautifier());
app.use(express.static(__dirname + '/html'));
-app.listen(8080);
+app.listen(8081);
View
29 lib/connect-stricten.js
@@ -1,16 +1,13 @@
exports.filterJS = function( req, res ) {
-
-// TODO don't test url.
return (
- /\.js/.test(req.url)
- && req.accepts('json') == 'json'
+ req.accepts('json') == 'json'
&& res.statusCode == 200
) ;
}
exports.filterHTML = function( req, res ) {
return (
- req.accepts('html') == 'html'
+ req.accepts('html') == 'html'
&& res.statusCode == 200
) ;
}
@@ -56,8 +53,6 @@ exports.beautifier = function(options) {
, isHTML = exports.filterHTML(req,res)
;
-
-
res.on('header', function( ) {
if( isJS || isHTML ) {
console.log('Url is ' + req.url );
@@ -68,7 +63,8 @@ exports.beautifier = function(options) {
res.removeHeader('last-modified');
}
if( res.get('Content-Type') ) {
- isJS = isJS && /javascript|json/.test(res.get('Content-Type'));
+ isJS = isJS && /javascript|json/i.test(res.get('Content-Type'));
+ isHTML = isHTML && /html/i.test(res.get('Content-Type'));
}
});
@@ -102,15 +98,15 @@ exports.beautifier = function(options) {
}
res.end = function(chunk,encoding) {
- if( isJS ) {
+ if( isJS && !isHTML ) {
if (chunk) body += chunk;
- console.log('beautifying ' + url);
+ console.log('beautifying (js) ' + url);
var ubody = exports.beautify( body ) ;
write.call(res,ubody,encoding);
end.call(res);
} else if ( isHTML ) {
if (chunk) body += chunk;
- console.log('beautifying ' + url);
+ console.log('beautifying (html) ' + url);
body = body.replace(/(<script[^>]*>)((?:.|\s)*?)(<\/script>)/mig, exports.beautify ) ;
write.call(res,body,encoding);
end.call(res);
@@ -144,12 +140,13 @@ exports.stricten = function(options) {
// Normal case
res.on('header', function( ) {
- if( isJS ) {
+ if( isJS || isHTML ) {
res.removeHeader('Content-Length');
res.removeHeader('last-modified'); // do not cache modification on-the-fly
}
if( res.get('Content-Type') ) {
- isJS = isJS && /javascript|json/.test(res.get('Content-Type'));
+ isJS = isJS && /javascript|json/i.test(res.get('Content-Type'));
+ isHTML = isHTML && /html/i.test(res.get('Content-Type'));
}
});
@@ -176,9 +173,9 @@ exports.stricten = function(options) {
res.write = function( chunk, encoding ) {
- if( isJS ) {
+ if( isJS && !isHTML ) {
called = true;
- console.log('strictening ' + url);
+ console.log('strictening (js) ' + url);
write.call(res, exports.strictening(chunk), encoding);
} else if ( isHTML ) {
if (chunk) body += chunk;
@@ -191,7 +188,7 @@ exports.stricten = function(options) {
res.end = function(chunk,encoding) {
if ( isHTML ) {
if (chunk) body += chunk;
- console.log('strictening ' + url);
+ console.log('strictening (html) ' + url);
body = body.replace(/(<script[^>]*>)((?:.|\s)*?)(<\/script>)/mig, exports.strictening ) ;
write.call(res,body,encoding);
end.call(res);

No commit comments for this range

Something went wrong with that request. Please try again.