Skip to content

Commit 06e69c9

Browse files
committed
Add Ruby Level 1
The test cases are adapted from https://github.com/web-platform-tests/wpt/tree/master/css/css-ruby/parsing Bug: T277755 Change-Id: I8fef917ea050a7f3a43eafae483d5565070569c1
1 parent 47f9f40 commit 06e69c9

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Update Color to Level 4 (2025-04-24)
88
* Update Values and Units to Level 4 (WD 2024-03-12)
99
* Update Display Level 3 to CR 2023-03-30
10+
* Add support for Ruby Level 1 (WD 2022-12-31)
1011

1112
## css-sanitizer 5.5.0 (2025-01-27)
1213
* Ensure <-token and identifiers are always separated as a security

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ The sanitizer recognizes the following CSS modules:
9393
* [Writing Modes Level 4, 2019-07-30](https://www.w3.org/TR/2019/CR-css-writing-modes-4-20190730)
9494
* [Selectors Level 4, 2019-02-25](https://www.w3.org/TR/2019/WD-css-pseudo-4-20190225/)
9595
* [Logical Properties and Values Level 1, 2018-08-27](https://www.w3.org/TR/2018/WD-css-logical-1-20180827/)
96+
* [Ruby Level 1, 2022-12-31](https://www.w3.org/TR/2022/WD-css-ruby-1-20221231/)
9697

9798
And also,
9899
* The `touch-action` property from

src/Sanitizer/StylePropertySanitizer.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function __construct( MatcherFactory $matcherFactory ) {
7878
$this->addKnownProperties( $this->cssMasking1( $matcherFactory ) );
7979
$this->addKnownProperties( $this->cssSizing4( $matcherFactory ) );
8080
$this->addKnownProperties( $this->cssLogical1( $matcherFactory ) );
81+
$this->addKnownProperties( $this->cssRuby1( $matcherFactory ) );
8182
}
8283

8384
/**
@@ -1928,4 +1929,27 @@ protected function cssLogical1( MatcherFactory $matcherFactory ) {
19281929
$this->cache[__METHOD__] = $props;
19291930
return $props;
19301931
}
1932+
1933+
/**
1934+
* Properties for CSS Ruby Annotation Layout Module Level 1
1935+
* @see https://www.w3.org/TR/2022/WD-css-ruby-1-20221231/
1936+
* @param MatcherFactory $matcherFactory
1937+
* @return Matcher[] Array mapping declaration names (lowercase) to Matchers for the values
1938+
*/
1939+
protected function cssRuby1( $matcherFactory ) {
1940+
return $this->cache[__METHOD__] ??= [
1941+
'ruby-position' => new Alternative( [
1942+
UnorderedGroup::someOf( [
1943+
new KeywordMatcher( 'alternate' ),
1944+
new KeywordMatcher( [ 'over', 'under' ] ),
1945+
] ),
1946+
new KeywordMatcher( [ 'inter-character' ] )
1947+
] ),
1948+
'ruby-merge' => new KeywordMatcher( [ 'separate', 'merge', 'auto' ] ),
1949+
'ruby-align' => new KeywordMatcher( [
1950+
'start', 'center', 'space-between', 'space-around '
1951+
] ),
1952+
'ruby-overhang' => new KeywordMatcher( [ 'auto', 'none' ] ),
1953+
];
1954+
}
19311955
}

tests/Sanitizer/StylePropertySanitizerTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,33 @@ public static function provideDeclarations() {
596596
[ 'border-start-end-radius: 0 5px' ],
597597
[ 'border-end-start-radius: 1em' ],
598598
[ 'border-end-end-radius: 5px 10px' ],
599+
600+
// cssRuby1
601+
[ 'ruby-merge: none', 'bad-value-for-property' ],
602+
[ 'ruby-merge: collapse', 'bad-value-for-property' ],
603+
[ 'ruby-merge: 10px', 'bad-value-for-property' ],
604+
[ 'ruby-merge: merge separate', 'bad-value-for-property' ],
605+
[ 'ruby-merge: merge auto', 'bad-value-for-property' ],
606+
[ 'ruby-merge: auto separate', 'bad-value-for-property' ],
607+
[ 'ruby-merge: separate' ],
608+
[ 'ruby-merge: merge' ],
609+
[ 'ruby-merge: auto' ],
610+
[ 'ruby-overhang: auto none', 'bad-value-for-property' ],
611+
[ 'ruby-overhang: none auto', 'bad-value-for-property' ],
612+
[ 'ruby-overhang: auto auto', 'bad-value-for-property' ],
613+
[ 'ruby-overhang: none none', 'bad-value-for-property' ],
614+
[ 'ruby-overhang: auto 2px', 'bad-value-for-property' ],
615+
[ 'ruby-overhang: none 2px', 'bad-value-for-property' ],
616+
[ 'ruby-overhang: auto' ],
617+
[ 'ruby-overhang: none' ],
618+
[ 'ruby-position: auto', 'bad-value-for-property' ],
619+
[ 'ruby-position: center', 'bad-value-for-property' ],
620+
[ 'ruby-position: above', 'bad-value-for-property' ],
621+
[ 'ruby-position: 10px 20px', 'bad-value-for-property' ],
622+
[ 'ruby-position: over under', 'bad-value-for-property' ],
623+
[ 'ruby-position: over' ],
624+
[ 'ruby-position: under' ],
625+
[ 'ruby-position: inter-character' ],
599626
];
600627
}
601628
}

0 commit comments

Comments
 (0)