Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #22

  • Loading branch information...
commit f8057a58087365029a55dc1580a66da7e49ae6df 1 parent 20b7f4a
@zachleat zachleat authored
View
5 src/respond.js
@@ -52,6 +52,7 @@
respond.regex = {
media: /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,
keyframes: /@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,
+ comments: /\/\*[^*]*\*+([^/][^*]*\*+)*\//gi,
urls: /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,
findStyles: /@media *([^\{]+)\{([\S\s]+?)$/,
only: /(only\s+)?([a-zA-Z]+)\s?/,
@@ -216,7 +217,9 @@
},
//find media blocks in css text, convert to style blocks
translate = function( styles, href, media ){
- var qs = styles.replace( respond.regex.keyframes, '' ).match( respond.regex.media ),
+ var qs = styles.replace( respond.regex.comments, '' )
+ .replace( respond.regex.keyframes, '' )
+ .match( respond.regex.media ),
ql = qs && qs.length || 0;
//try to get CSS path
View
29 test/unit/test-with-comment.css
@@ -0,0 +1,29 @@
+/* this is a comment
+ *
+ */
+
+@media (min-width: 1px) {
+
+ /* see issue #22 */
+ /* @media {} */
+ /* @media {
+ } */
+
+ /* this is a comment
+ *
+ */
+
+ /* * / /*
+ Will this strip right?
+ */
+ body {
+ color: red;
+ /* TODO This edge case is not currently supported */
+ content: "content /* this should not strip */";
+ }
+
+ /* this is a comment */
+
+ /* see issue #22 */
+ /* @media */
+}
View
15 test/unit/tests.js
@@ -156,7 +156,6 @@ window.onload = function(){
}, 900);
});
- // This test will only run on IE8 since the respond ajax stuff isn’t exposed yet
asyncTest( 'Test keyframe animation inside of media query', function() {
queueRequest( function() {
respond.ajax( getNormalizedUrl( 'test-with-keyframe.css' ),
@@ -167,6 +166,20 @@ window.onload = function(){
});
});
+ asyncTest( 'Test comments inside of a media query', function() {
+ queueRequest( function() {
+ respond.ajax( getNormalizedUrl( 'test-with-comment.css' ),
+ function( data ) {
+ var stripped = data.replace( respond.regex.comments, '' );
+ // TODO allow /* */ inside of CSS content strings.
+ ok( stripped.match( respond.regex.media ), 'Comments don\'t bust the media regex.' );
+ ok( !stripped.match( /\/\*/gi ), 'No start comments exist in the result.' );
+ ok( !stripped.match( /\*\//gi ), 'No end comments exist in the result.' );
+ start();
+ });
+ });
+ });
+
test( 'Issue #242 overly agressive keyframes regex', function() {
strictEqual( '@media(q1){ @keyframes abc{ from{ }to{ } } } @media(q2){}'.replace( respond.regex.keyframes, '' ), '@media(q1){ } @media(q2){}' );
strictEqual( '@media(q1){} @keyframes abc{ from{ }to{ } } @media(q2){}'.replace( respond.regex.keyframes, '' ), '@media(q1){} @media(q2){}' );
Please sign in to comment.
Something went wrong with that request. Please try again.