-
Notifications
You must be signed in to change notification settings - Fork 233
Support more HTML elements and CSS attributes and fix CSS filter crashes #990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8584c21
Allow bdi and main elements and auto value of dir attribute
torusrxxx 7cf3133
Add elements figcaption,figure,mark,rp,rt,ruby
torusrxxx 35a00bf
Add CSS global values revert,revert-layer, attribute writing-mode, up…
torusrxxx 453a446
Add CSS colors rebeccapurple and rgba modern format
torusrxxx 3d857a5
Add fonts system-ui,ui-serif,ui-sans-serif,ui-monospace,ui-rounded,em…
torusrxxx 8617f30
Add more pseudo classes
torusrxxx ba0d911
Add inline-start,inline-end values of float CSS attribute
torusrxxx 278a10f
Update CSS attributes clear,overflow,text-underline-position
torusrxxx 86f216d
Fix StringIndexOutOfBoundsException when filtering "tr:tenth-child {}"
torusrxxx 46f36f7
Add font size xxx-large and selector tests
torusrxxx 5e0d013
Add background-blend-mode and mix-blend-mode and CSS tests
torusrxxx e33b534
Fix text-shadow parsing
torusrxxx c814ae1
Add attributes block-size,inline-size, length values min-content,max-…
torusrxxx cc74d98
fix NullPointerException with text-emphasis, fix deprecated attribute…
torusrxxx 9591dba
Add tab-size,font-kerning, update word-break
torusrxxx 47e72cc
Add object-fit
torusrxxx 598c52f
Support "reversed" attribute of <ol> element
torusrxxx 5b9f643
Add more types to list-style-type and also allow string
torusrxxx 2dc724b
Add max-block-size,max-inline-size,min-block-size,min-inline-size
torusrxxx 2bc2fc2
Fix text-wrap having nonstandard values
torusrxxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.HashSet; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class FilterUtils { | ||
| private static volatile boolean logDEBUG; | ||
|
|
@@ -289,6 +290,7 @@ else if(value.contains("rad")) | |
| SVGcolorKeywords.add("whitesmoke"); | ||
| SVGcolorKeywords.add("yellow"); | ||
| SVGcolorKeywords.add("yellowgreen"); | ||
| SVGcolorKeywords.add("rebeccapurple"); // CSS Colors Level 4: #663399 | ||
| } | ||
| private final static HashSet<String> CSScolorKeywords=new HashSet<String>(); | ||
| static | ||
|
|
@@ -315,34 +317,34 @@ else if(value.contains("rad")) | |
| } | ||
| private final static HashSet<String> CSSsystemColorKeywords=new HashSet<String>(); | ||
| static { | ||
| CSScolorKeywords.add("ActiveBorder"); | ||
| CSScolorKeywords.add("ActiveCaption"); | ||
| CSScolorKeywords.add("AppWorkspace"); | ||
| CSScolorKeywords.add("Background"); | ||
| CSScolorKeywords.add("ButtonFace"); | ||
| CSScolorKeywords.add("ButtonHighlight"); | ||
| CSScolorKeywords.add("ButtonShadow"); | ||
| CSScolorKeywords.add("ButtonText"); | ||
| CSScolorKeywords.add("CaptionText"); | ||
| CSScolorKeywords.add("GrayText"); | ||
| CSScolorKeywords.add("Highlight"); | ||
| CSScolorKeywords.add("HighlightText"); | ||
| CSScolorKeywords.add("InactiveBorder"); | ||
| CSScolorKeywords.add("InactiveCaption"); | ||
| CSScolorKeywords.add("InactiveCaptionText"); | ||
| CSScolorKeywords.add("InfoBackground"); | ||
| CSScolorKeywords.add("InfoText"); | ||
| CSScolorKeywords.add("Menu"); | ||
| CSScolorKeywords.add("MenuText"); | ||
| CSScolorKeywords.add("Scrollbar"); | ||
| CSScolorKeywords.add("ThreeDDarkShadow"); | ||
| CSScolorKeywords.add("ThreeDFace"); | ||
| CSScolorKeywords.add("ThreeDHighlight"); | ||
| CSScolorKeywords.add("ThreeDLightShadow"); | ||
| CSScolorKeywords.add("ThreeDShadow"); | ||
| CSScolorKeywords.add("Window"); | ||
| CSScolorKeywords.add("WindowFrame"); | ||
| CSScolorKeywords.add("WindowText"); | ||
| CSScolorKeywords.add("activeborder"); | ||
| CSScolorKeywords.add("activecaption"); | ||
| CSScolorKeywords.add("appworkspace"); | ||
| CSScolorKeywords.add("background"); | ||
| CSScolorKeywords.add("buttonface"); | ||
| CSScolorKeywords.add("buttonhighlight"); | ||
| CSScolorKeywords.add("buttonshadow"); | ||
| CSScolorKeywords.add("buttontext"); | ||
| CSScolorKeywords.add("captiontext"); | ||
| CSScolorKeywords.add("graytext"); | ||
| CSScolorKeywords.add("highlight"); | ||
| CSScolorKeywords.add("highlighttext"); | ||
| CSScolorKeywords.add("inactiveborder"); | ||
| CSScolorKeywords.add("inactivecaption"); | ||
| CSScolorKeywords.add("inactivecaptiontext"); | ||
| CSScolorKeywords.add("infobackground"); | ||
| CSScolorKeywords.add("infotext"); | ||
| CSScolorKeywords.add("menu"); | ||
| CSScolorKeywords.add("menutext"); | ||
| CSScolorKeywords.add("scrollbar"); | ||
| CSScolorKeywords.add("threeddarkshadow"); | ||
| CSScolorKeywords.add("threedface"); | ||
| CSScolorKeywords.add("threedhighlight"); | ||
| CSScolorKeywords.add("threedlightshadow"); | ||
| CSScolorKeywords.add("threedshadow"); | ||
| CSScolorKeywords.add("window"); | ||
| CSScolorKeywords.add("windowframe"); | ||
| CSScolorKeywords.add("windowtext"); | ||
| } | ||
| public static boolean isValidCSSShape(String value) | ||
| { | ||
|
|
@@ -370,70 +372,57 @@ public static boolean isValidCSSShape(String value) | |
| public static boolean isMedia(String media) { | ||
| return cssMedia.contains(media); | ||
| } | ||
|
|
||
| public static final Pattern hexColorPattern = Pattern.compile("#(?>[0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{3,4})", Pattern.CASE_INSENSITIVE); | ||
|
|
||
| public static boolean isColor(String value) | ||
| { | ||
| value=value.trim(); | ||
| value=value.trim().toLowerCase(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch! (feel free to mark this resolved once you read it ☺) |
||
|
|
||
| if(CSScolorKeywords.contains(value) || CSSsystemColorKeywords.contains(value) || SVGcolorKeywords.contains(value)) | ||
| return true; | ||
|
|
||
| if(value.indexOf('#')==0) | ||
| { | ||
|
|
||
| if(value.length()==4) | ||
| return hexColorPattern.matcher(value).matches(); | ||
| } | ||
| if((value.startsWith("rgb(") || value.startsWith("rgba(")) && value.indexOf(')')==value.length()-1) | ||
| { | ||
| // rgba is an alias to rgb | ||
| if(value.contains(",")) | ||
| { | ||
| try{ | ||
| Integer.valueOf(value.substring(1,2),16).intValue(); | ||
| Integer.valueOf(value.substring(2,3),16).intValue(); | ||
| Integer.valueOf(value.substring(3,4),16).intValue(); | ||
| return true; | ||
| } | ||
| catch(Exception e) | ||
| // Legacy format rgba(r,g,b,a) | ||
| String[] colorParts=value.substring(value.indexOf("(")+1,value.length()-1).split(","); | ||
| if(colorParts.length!=3&&colorParts.length!=4) | ||
| return false; | ||
| for(int i=0; i<3; i++) | ||
| { | ||
| if(!(isPercentage(colorParts[i].trim()) || isInteger(colorParts[i].trim()))) | ||
| return false; | ||
| } | ||
|
|
||
| } | ||
| else if(value.length()==7) | ||
| { | ||
|
|
||
| try{ | ||
| Integer.valueOf(value.substring(1,3),16).intValue(); | ||
| Integer.valueOf(value.substring(3,5),16).intValue(); | ||
| Integer.valueOf(value.substring(5,7),16).intValue(); | ||
| if(colorParts.length<=3 || isNumber(colorParts[3])) | ||
| return true; | ||
| }else{ | ||
| if(value.contains("/")){ | ||
| // Modern format rgba(r g b / a) | ||
| String alphaPart=value.substring(value.indexOf("/")+1,value.length()-1).trim(); | ||
| if(!alphaPart.isEmpty() && !isPercentage(alphaPart) && !isNumber(alphaPart) && !alphaPart.equalsIgnoreCase("none")) | ||
| return false; | ||
| value=value.substring(0,value.indexOf("/"))+")"; // Strip alpha value, proceed to the following tests | ||
| } | ||
| // Modern format rgba(r g b) | ||
| String[] colorParts=value.substring(value.indexOf("(")+1,value.length()-1).split(" "); | ||
| if(colorParts.length!=3) { | ||
| return false; | ||
| } | ||
| catch(Exception e) | ||
| for(int i=0; i<3; i++) | ||
| { | ||
| String trimmed = colorParts[i].trim(); | ||
| if(!(trimmed.equalsIgnoreCase("none") || isPercentage(trimmed) || (isInteger(trimmed) && isIntegerInRange(trimmed, 0, 255)))) | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| if(value.indexOf("rgb(")==0 && value.indexOf(')')==value.length()-1) | ||
| { | ||
| String[] colorParts=value.substring(4,value.length()-1).split(","); | ||
| if(colorParts.length!=3) | ||
| return false; | ||
| boolean isValidColorParts=true; | ||
| for(int i=0; i<colorParts.length && isValidColorParts;i++) | ||
| { | ||
| if(!(isPercentage(colorParts[i].trim()) || isInteger(colorParts[i].trim()))) | ||
| isValidColorParts = false; | ||
| } | ||
| if(isValidColorParts) | ||
| return true; | ||
| } | ||
| if(value.indexOf("rgba(")==0 && value.indexOf(')')==value.length()-1) | ||
| { | ||
| String[] colorParts=value.substring(5,value.length()-1).split(","); | ||
| if(colorParts.length!=4) | ||
| return false; | ||
| boolean isValidColorParts=true; | ||
| for(int i=0; i<colorParts.length-1 && isValidColorParts;i++) | ||
| { | ||
| if(!(isPercentage(colorParts[i].trim()) || isInteger(colorParts[i].trim()))) | ||
| isValidColorParts = false; | ||
| } | ||
| if(isValidColorParts && isNumber(colorParts[3])) | ||
| return true; | ||
| } | ||
|
|
||
| if(value.indexOf("hsl(")==0 && value.indexOf(')')==value.length()-1) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.