Skip to content

Commit

Permalink
Make <<foo>> inside of maybe autolinks a little safer again.
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed May 13, 2024
1 parent 72b9cfa commit 252612a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 48 deletions.
16 changes: 11 additions & 5 deletions bikeshed/h/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ def parseNode(
elif first2 == r"\'":
node = RawText.fromStream(s, start, start + 2, "'")
return Result(node, start + 2)
elif first3 == "\\<<":
node = SafeText.fromStream(s, start, start+3, "<<")
return Result(node, start + 3)
elif first2 == "''":
maybeRes = parseCSSMaybe(s, start)
if maybeRes.valid:
Expand All @@ -203,6 +206,14 @@ def parseNode(
lineNum=s.loc(start),
)
return propdescRes
elif first2 == "<<":
if inA:
m.die("Parsed a CSS production autolink (<<foo>>) inside of an <a> or another autolink. Either close the <a> properly, or escape the autolink.", lineNum=s.loc(start))
node = SafeText.fromStream(s, start, start+2)
return Result(node, start+2)
prodRes = parseCSSProduction(s, start)
if prodRes.valid:
return prodRes
if s.config.dfn and not inOpaque:
if first3 in ("\\[=", "\\[$"):
node = RawText.fromStream(s, start, start + 3, "[" + s[start + 2])
Expand Down Expand Up @@ -356,11 +367,6 @@ def parseAngleStart(s: Stream, start: int) -> Result[ParserNode | list[ParserNod
if endTag is not None:
return Result(endTag, i)

if s.config.css:
els, i = parseCSSProduction(s, start).vi
if els is not None:
return Result(els, i)

return Result.fail(start)


Expand Down
32 changes: 16 additions & 16 deletions tests/github/w3c/csswg-drafts/css-box-3/block-layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -1777,10 +1777,10 @@ <h2 class="heading settled" data-level="9" id="margin-props"><span class="secno"
</div>
<p class="note" role="note">Note that inside flexboxes <a data-link-type="biblio" href="#biblio-css3-flexbox" title="CSS Flexible Box Layout Module Level 1">[CSS3-FLEXBOX]</a>, the meaning
of <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-align-3/#valdef-align-self-auto" id="ref-for-valdef-align-self-auto②">auto</a> is different, because there it also has an effect on the <em>A edge</em> and <em>C edge.</em> </p>
<p class="issue" id="issue-866adfaa"><a class="self-link" href="#issue-866adfaa"></a>One idea to distribute boxes better than with <a class="property css" data-link-type="property">auto</a> (which only works in the inline direction and fails to distribute
<p class="issue" id="issue-1977cb87"><a class="self-link" href="#issue-1977cb87"></a>One idea to distribute boxes better than with <a class="property css" data-link-type="property">auto</a> (which only works in the inline direction and fails to distribute
negative space) is to add a “fill” keyword, possibly combined with a
minimum margin: <span class="css">fill</span> or <span class="css">1.2em + fill</span> or ''calc(1.2em +
fill)''). “Fill” could also be a unit, so that some fills can get more
minimum margin: <span class="css">fill</span> or <span class="css">1.2em + fill</span> or <span class="css">calc(1.2em +
fill)</span>). “Fill” could also be a unit, so that some fills can get more
space than others: <a class="css" data-link-type="propdesc" href="#propdef-margin" id="ref-for-propdef-margin②">margin: 0.5fill</a> or <span class="css" id="ref-for-propdef-margin③">margin: 2fill</span>. </p>
<p class="issue" id="issue-68cb5405"><a class="self-link" href="#issue-68cb5405"></a>Andrew Fedoniouk proposed the '%%' unit. '50%%' is 50%
of the remaining space. This allows fills to sum up to more or less
Expand Down Expand Up @@ -3296,8 +3296,8 @@ <h2 class="heading settled" data-level="18" id="clear-after-prop"><span class="s
<dd>All floats in the element’s flow that are descendants of the
element are considered, but not any other floats.
</dl>
<div class="example" id="example-e7ea91dc">
<a class="self-link" href="#example-e7ea91dc"></a>
<div class="example" id="example-cc26e659">
<a class="self-link" href="#example-cc26e659"></a>
<p>In simple cases, the effect of 'overflow: hidden' can be quite
similar to 'clear-after: both', e.g., this documents looks the same whether it contains <a class="css" data-link-type="propdesc" href="#propdef-overflow" id="ref-for-propdef-overflow⑦">overflow: hidden</a> or <a class="css" data-link-type="propdesc" href="#propdef-clear-after" id="ref-for-propdef-clear-after⑦">clear-after: both</a>: </p>
<pre><b>&lt;html></b>
Expand Down Expand Up @@ -3337,8 +3337,8 @@ <h2 class="heading settled" data-level="18" id="clear-after-prop"><span class="s
</div>
<div class="figure">
<p><img alt="[screendump]" src="clear-after6.png"> </p>
<p class="caption">With <a class="css" data-link-type="propdesc" href="#propdef-clear-after" id="ref-for-propdef-clear-after⑧">clear-after: both</a> instead of ''overflow:
hidden'', the floating box before the DIV doesn’t change the width of
<p class="caption">With <a class="css" data-link-type="propdesc" href="#propdef-clear-after" id="ref-for-propdef-clear-after⑧">clear-after: both</a> instead of <span class="css">overflow:
hidden</span>, the floating box before the DIV doesn’t change the width of
the DIV, but it <em>does</em> change the height. </p>
</div>
</div>
Expand Down Expand Up @@ -3562,10 +3562,10 @@ <h3 class="heading settled" data-level="19.1" id="overflow-props"><span class="s
first, perform all the collapsing of margins, and check that the
content height is indeed less than the <span class="property" id="ref-for-propdef-max-height⑦">max-height</span>. If it is not, the
process is repeated under the assumption that a scrolling mechanism <em>is</em> needed. </p>
<div class="example" id="example-ca1be1b7">
<a class="self-link" href="#example-ca1be1b7"></a>
<p>In the following document fragment, the outer DIV has ''height:
auto<span class="css">, but </span>max-height: 5em''. The inner DIV has large margins and
<div class="example" id="example-fdd56fad">
<a class="self-link" href="#example-fdd56fad"></a>
<p>In the following document fragment, the outer DIV has <span class="css">height:
auto</span>, but <a class="css" data-link-type="propdesc" href="#propdef-max-height" id="ref-for-propdef-max-height⑧">max-height: 5em</a>. The inner DIV has large margins and
would normally just fit: </p>
<pre>...
#d1 { overflow: auto; max-height: 5em }
Expand Down Expand Up @@ -4909,7 +4909,7 @@ <h2 class="no-num no-ref heading settled" id="property-index"><span class="conte
<td>the percentage as specified or the
absolute length or auto
<tr>
<th scope="row"><a class="css" data-link-type="property" href="#propdef-max-height" id="ref-for-propdef-max-height">max-height</a>
<th scope="row"><a class="css" data-link-type="property" href="#propdef-max-height" id="ref-for-propdef-max-height">max-height</a>
<td>[ [&lt;length> |
&lt;percentage>] &amp;&amp; [border-box | content-box]? ] |
available | min-content | max-content | fit-content | none
Expand Down Expand Up @@ -5205,9 +5205,9 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
</div>
<div class="issue">One idea to distribute boxes better than with <a class="property css" data-link-type="property">auto</a> (which only works in the inline direction and fails to distribute
negative space) is to add a “fill” keyword, possibly combined with a
minimum margin: <span class="css">fill</span> or <span class="css">1.2em + fill</span> or ''calc(1.2em +
fill)''). “Fill” could also be a unit, so that some fills can get more
space than others: <a class="css" data-link-type="propdesc" href="#propdef-margin">margin: 0.5fill</a> or <span class="css">margin: 2fill</span>. <a class="issue-return" href="#issue-866adfaa" title="Jump to section">↵</a></div>
minimum margin: <span class="css">fill</span> or <span class="css">1.2em + fill</span> or <span class="css">calc(1.2em +
fill)</span>). “Fill” could also be a unit, so that some fills can get more
space than others: <a class="css" data-link-type="propdesc" href="#propdef-margin">margin: 0.5fill</a> or <span class="css">margin: 2fill</span>. <a class="issue-return" href="#issue-1977cb87" title="Jump to section">↵</a></div>
<div class="issue">Andrew Fedoniouk proposed the '%%' unit. '50%%' is 50%
of the remaining space. This allows fills to sum up to more or less
than 100%. More than 100% is probably not useful, it guarantees
Expand Down Expand Up @@ -5634,7 +5634,7 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
"propdef-margin-left": {"dfnID":"propdef-margin-left","dfnText":"margin-left","external":false,"refSections":[{"refs":[{"id":"ref-for-propdef-margin-left"}],"title":"9. The margin properties"},{"refs":[{"id":"ref-for-propdef-margin-left\u2460"}],"title":"15.1. Inline, non-replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-left\u2461"}],"title":"15.2. Inline or floating, replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-left\u2462"}],"title":"15.5. Inline-block or floating, non-replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-left\u2463"},{"id":"ref-for-propdef-margin-left\u2464"},{"id":"ref-for-propdef-margin-left\u2465"},{"id":"ref-for-propdef-margin-left\u2466"},{"id":"ref-for-propdef-margin-left\u2467"},{"id":"ref-for-propdef-margin-left\u2468"},{"id":"ref-for-propdef-margin-left\u2460\u24ea"}],"title":"15.6. Absolutely positioned, non-replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-left\u2460\u2460"},{"id":"ref-for-propdef-margin-left\u2460\u2461"},{"id":"ref-for-propdef-margin-left\u2460\u2462"},{"id":"ref-for-propdef-margin-left\u2460\u2463"},{"id":"ref-for-propdef-margin-left\u2460\u2464"},{"id":"ref-for-propdef-margin-left\u2460\u2465"},{"id":"ref-for-propdef-margin-left\u2460\u2466"}],"title":"15.7. Absolutely positioned, replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-left\u2460\u2467"}],"title":"15.8. Block-level, replaced elements in normal flow"}],"url":"#propdef-margin-left"},
"propdef-margin-right": {"dfnID":"propdef-margin-right","dfnText":"margin-right","external":false,"refSections":[{"refs":[{"id":"ref-for-propdef-margin-right"}],"title":"9. The margin properties"},{"refs":[{"id":"ref-for-propdef-margin-right\u2460"}],"title":"15.1. Inline, non-replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-right\u2461"}],"title":"15.2. Inline or floating, replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-right\u2462"}],"title":"15.5. Inline-block or floating, non-replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-right\u2463"},{"id":"ref-for-propdef-margin-right\u2464"},{"id":"ref-for-propdef-margin-right\u2465"},{"id":"ref-for-propdef-margin-right\u2466"},{"id":"ref-for-propdef-margin-right\u2467"},{"id":"ref-for-propdef-margin-right\u2468"},{"id":"ref-for-propdef-margin-right\u2460\u24ea"}],"title":"15.6. Absolutely positioned, non-replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-right\u2460\u2460"},{"id":"ref-for-propdef-margin-right\u2460\u2461"},{"id":"ref-for-propdef-margin-right\u2460\u2462"},{"id":"ref-for-propdef-margin-right\u2460\u2463"},{"id":"ref-for-propdef-margin-right\u2460\u2464"},{"id":"ref-for-propdef-margin-right\u2460\u2465"},{"id":"ref-for-propdef-margin-right\u2460\u2466"}],"title":"15.7. Absolutely positioned, replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-right\u2460\u2467"}],"title":"15.8. Block-level, replaced elements in normal flow"}],"url":"#propdef-margin-right"},
"propdef-margin-top": {"dfnID":"propdef-margin-top","dfnText":"margin-top","external":false,"refSections":[{"refs":[{"id":"ref-for-propdef-margin-top"}],"title":"9. The margin properties"},{"refs":[{"id":"ref-for-propdef-margin-top\u2460"}],"title":"15.1. Inline, non-replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-top\u2461"}],"title":"15.2. Inline or floating, replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-top\u2462"}],"title":"15.5. Inline-block or floating, non-replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-top\u2463"},{"id":"ref-for-propdef-margin-top\u2464"},{"id":"ref-for-propdef-margin-top\u2465"},{"id":"ref-for-propdef-margin-top\u2466"},{"id":"ref-for-propdef-margin-top\u2467"},{"id":"ref-for-propdef-margin-top\u2468"},{"id":"ref-for-propdef-margin-top\u2460\u24ea"},{"id":"ref-for-propdef-margin-top\u2460\u2460"},{"id":"ref-for-propdef-margin-top\u2460\u2461"}],"title":"15.6. Absolutely positioned, non-replaced\nelements"},{"refs":[{"id":"ref-for-propdef-margin-top\u2460\u2462"},{"id":"ref-for-propdef-margin-top\u2460\u2463"}],"title":"15.7. Absolutely positioned, replaced\nelements"}],"url":"#propdef-margin-top"},
"propdef-max-height": {"dfnID":"propdef-max-height","dfnText":"max-height","external":false,"refSections":[{"refs":[{"id":"ref-for-propdef-max-height"},{"id":"ref-for-propdef-max-height\u2460"}],"title":"11. The min-width, max-width, min-height and\nmax-height properties"},{"refs":[{"id":"ref-for-propdef-max-height\u2461"}],"title":"13. Collapsing margins"},{"refs":[{"id":"ref-for-propdef-max-height\u2462"},{"id":"ref-for-propdef-max-height\u2463"},{"id":"ref-for-propdef-max-height\u2464"}],"title":"15. Calculating widths, heights and margins"},{"refs":[{"id":"ref-for-propdef-max-height\u2465"},{"id":"ref-for-propdef-max-height\u2466"}],"title":"19.1. The overflow, overflow-x and overflow-y properties"}],"url":"#propdef-max-height"},
"propdef-max-height": {"dfnID":"propdef-max-height","dfnText":"max-height","external":false,"refSections":[{"refs":[{"id":"ref-for-propdef-max-height"},{"id":"ref-for-propdef-max-height\u2460"}],"title":"11. The min-width, max-width, min-height and\nmax-height properties"},{"refs":[{"id":"ref-for-propdef-max-height\u2461"}],"title":"13. Collapsing margins"},{"refs":[{"id":"ref-for-propdef-max-height\u2462"},{"id":"ref-for-propdef-max-height\u2463"},{"id":"ref-for-propdef-max-height\u2464"}],"title":"15. Calculating widths, heights and margins"},{"refs":[{"id":"ref-for-propdef-max-height\u2465"},{"id":"ref-for-propdef-max-height\u2466"},{"id":"ref-for-propdef-max-height\u2467"}],"title":"19.1. The overflow, overflow-x and overflow-y properties"}],"url":"#propdef-max-height"},
"propdef-max-width": {"dfnID":"propdef-max-width","dfnText":"max-width","external":false,"refSections":[{"refs":[{"id":"ref-for-propdef-max-width"},{"id":"ref-for-propdef-max-width\u2460"}],"title":"11. The min-width, max-width, min-height and\nmax-height properties"},{"refs":[{"id":"ref-for-propdef-max-width\u2461"},{"id":"ref-for-propdef-max-width\u2462"},{"id":"ref-for-propdef-max-width\u2463"}],"title":"15. Calculating widths, heights and margins"}],"url":"#propdef-max-width"},
"propdef-min-height": {"dfnID":"propdef-min-height","dfnText":"min-height","external":false,"refSections":[{"refs":[{"id":"ref-for-propdef-min-height"},{"id":"ref-for-propdef-min-height\u2460"}],"title":"11. The min-width, max-width, min-height and\nmax-height properties"},{"refs":[{"id":"ref-for-propdef-min-height\u2461"},{"id":"ref-for-propdef-min-height\u2462"},{"id":"ref-for-propdef-min-height\u2463"}],"title":"13. Collapsing margins"},{"refs":[{"id":"ref-for-propdef-min-height\u2464"},{"id":"ref-for-propdef-min-height\u2465"},{"id":"ref-for-propdef-min-height\u2466"}],"title":"15. Calculating widths, heights and margins"},{"refs":[{"id":"ref-for-propdef-min-height\u2467"}],"title":"18. The clear-after property"}],"url":"#propdef-min-height"},
"propdef-min-width": {"dfnID":"propdef-min-width","dfnText":"min-width","external":false,"refSections":[{"refs":[{"id":"ref-for-propdef-min-width"},{"id":"ref-for-propdef-min-width\u2460"}],"title":"11. The min-width, max-width, min-height and\nmax-height properties"},{"refs":[{"id":"ref-for-propdef-min-width\u2461"},{"id":"ref-for-propdef-min-width\u2462"}],"title":"13. Collapsing margins"},{"refs":[{"id":"ref-for-propdef-min-width\u2463"},{"id":"ref-for-propdef-min-width\u2464"},{"id":"ref-for-propdef-min-width\u2465"}],"title":"15. Calculating widths, heights and margins"}],"url":"#propdef-min-width"},
Expand Down
16 changes: 8 additions & 8 deletions tests/github/w3c/csswg-drafts/css-device-adapt-1/Overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -1477,8 +1477,8 @@ <h3 class="heading settled" data-level="6.1" id="min-max-width-desc"><span class
and vertical lengths respectively. Must be non-negative.
</dl>
<p>The <a class="property css" data-link-type="property" href="https://drafts.csswg.org/css-sizing-3/#propdef-min-width" id="ref-for-propdef-min-width①">min-width</a> and <a class="property css" data-link-type="property" href="https://drafts.csswg.org/css-sizing-3/#propdef-max-width" id="ref-for-propdef-max-width①">max-width</a> descriptors are inputs to the <a href="#constraining-procedure">constraining procedure</a>. The
width will initially be set as close as possible to the ''initial
viewport'' width within the min/max constraints.</p>
width will initially be set as close as possible to the <span class="css">initial
viewport</span> width within the min/max constraints.</p>
<h3 class="heading settled" data-level="6.2" id="width-desc"><span class="secno">6.2. </span><span class="content"> The <a class="property css" data-link-type="property" href="https://drafts.csswg.org/css-sizing-3/#propdef-width" id="ref-for-propdef-width">width</a> shorthand descriptor</span><a class="self-link" href="#width-desc"></a></h3>
<table class="def descdef">
<tbody>
Expand Down Expand Up @@ -1549,8 +1549,8 @@ <h3 class="heading settled" data-level="6.3" id="min-max-height-desc"><span clas
<p>Specifies the minimum and maximum height of the <a href="https://www.w3.org/TR/CSS21/visuren.html#viewport">viewport</a> that is used to set the size of the <a href="https://www.w3.org/TR/CSS21/visudet.html#containing-block-details"> initial containing block</a>.</p>
<p>The min-height and max-height descriptors are inputs to
the <a href="#constraining-procedure">constraining procedure</a>.
The height will initially be set as close as possible to the ''initial
viewport'' height within the min/max constraints.</p>
The height will initially be set as close as possible to the <span class="css">initial
viewport</span> height within the min/max constraints.</p>
<h3 class="heading settled" data-level="6.4" id="height-desc"><span class="secno">6.4. </span><span class="content"> The <a class="property css" data-link-type="property" href="https://drafts.csswg.org/css-sizing-3/#propdef-height" id="ref-for-propdef-height">height</a> shorthand descriptor</span><a class="self-link" href="#height-desc"></a></h3>
<table class="def descdef">
<tbody>
Expand Down Expand Up @@ -1799,8 +1799,8 @@ <h3 class="heading settled" data-level="7.2" id="constraining-procedure"><span c
<p>User agents are expected, but not required, to re-run this procedure
and re-layout the document, if necessary, in response to changes
in the user environment, for example if the device is tilted from
landscape to portrait mode or the window that forms the ''initial
viewport'' is resized.</p>
landscape to portrait mode or the window that forms the <span class="css">initial
viewport</span> is resized.</p>
<p>However, Media Queries and Device Adaption are <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="Specifications
whose evaluations are both affected by the same changes to the user
environment, and so always must be evaluated together in order to
Expand Down Expand Up @@ -1875,8 +1875,8 @@ <h2 class="heading settled" data-level="8" id="media-queries"><span class="secno
given that the UA stylesheet has a viewport width of 980px, but an <span class="css">initial viewport</span> width of 320px. The author has made separate
styles to make the document look good for initial containing block
widths above or below 400px. The <span class="css">actual viewport</span> used will be
320px wide, and in order to match the styles with the ''actual
viewport'' width, the viewport resulting from applying the <span class="css" id="ref-for-at-ruledef-viewport②⑦">@viewport</span> rules should be used to evaluate the media queries. </p>
320px wide, and in order to match the styles with the <span class="css">actual
viewport</span> width, the viewport resulting from applying the <span class="css" id="ref-for-at-ruledef-viewport②⑦">@viewport</span> rules should be used to evaluate the media queries. </p>
<div class="example" id="example-b47882d5">
<a class="self-link" href="#example-b47882d5"></a> Given an initial viewport width of 320px and a UA stylesheet viewport
width of 980px, the first media query will not match, but the second will.
Expand Down
Loading

0 comments on commit 252612a

Please sign in to comment.