forked from wet-boew/wet-boew
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch - Core: Ensure wb.getId() always returns unique IDs (wet-boew#9776
) WET core's getId() method was initially designed to increment a seed number in conjunction with a WET-specific auto ID naming scheme ("wb-auto-#"). That's fine in theory, but doesn't guarantee that it'll return a unique ID. It can clash with hardcoded IDs that use the same naming scheme - such as pages whose authors mistakenly-hardcode "post-JS" HTML markup generated by plugins. For example, if a "botched" plugin implementation contains a hardcoded "wb-auto-5" ID... wb.getId() might independently generate the same ID and return it to a "good" plugin somewhere else in the page. End result is that the "good" plugin will insert a duplicate ID into the page and possibly even break. This resolves the potential for clashes by revising getId() to: * Check for conflicting hardcoded IDs the first time it's called * Increment its initial seed number if needed (to surpass the highest conflicting ID's number) * Show console errors for any hardcoded IDs starting with WET's auto ID prefix (wb-auto-) Also adds a WET core working examples page to demonstrate an ID conflict scenario in action. Thanks to @fsnoddy for initially spotting this and providing insight.
- Loading branch information
1 parent
020057d
commit f81edda
Showing
5 changed files
with
280 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
{ | ||
"title": "WET core", | ||
"language": "en", | ||
"category": "Other", | ||
"description": "Working examples of WET core's built-in methods.", | ||
"tag": "core", | ||
"parentdir": "core", | ||
"altLangPrefix": "core", | ||
"dateModified": "2024-07-02" | ||
} | ||
--- | ||
|
||
<div class="wb-prettify all-pre hide"></div> | ||
|
||
<p>{{description}}</p> | ||
|
||
<nav> | ||
<h2>On this page</h2> | ||
<ul> | ||
<li><a href="#ex1">Example 1 - <code>wb.getId()</code> and ID conflicts</a></li> | ||
</ul> | ||
</nav> | ||
|
||
<section> | ||
<h2 id="ex1">Example 1 - <code>wb.getId()</code> and ID conflicts</h2> | ||
<p>Demonstrates how <code>wb.getId()</code> reacts when hardcoded IDs conflict with its naming convention (anything starting with <code>wb-auto-</code>).</p> | ||
|
||
<section> | ||
<h3>Hardcoded IDs</h3> | ||
<ul> | ||
<li id="wb-auto-"><code>wb-auto-</code></li> | ||
<li id="wb-auto-3abc"><code>wb-auto-3abc</code></li> | ||
<li id="wb-auto-4."><code>wb-auto-4.</code></li> | ||
<li id="wb-auto-17"><code>wb-auto-17</code></li> | ||
<li id="wb-auto-5.0"><code>wb-auto-5.0</code></li> | ||
<li id="wb-auto-1"><code>wb-auto-1</code></li> | ||
<li id="wb-auto-6.1"><code>wb-auto-6.1</code></li> | ||
<li id="wb-auto-2"><code>wb-auto-2</code></li> | ||
<li id="wb-auto-abc9"><code>wb-auto-abc9</code></li> | ||
</ul> | ||
</section> | ||
|
||
<section> | ||
<h3>Tables plugin</h3> | ||
<p>This plugin calls <code>wb.getId()</code>.</p> | ||
<table class="wb-tables table"> | ||
<thead> | ||
<tr> | ||
<th>Rendering engine</th> | ||
<th>Browser</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>Blink</td> | ||
<td>Chromium</td> | ||
</tr> | ||
<tr> | ||
<td>Gecko</td> | ||
<td>Firefox</td> | ||
</tr> | ||
<tr> | ||
<td>WebKit</td> | ||
<td>Safari</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</section> | ||
|
||
<h3>Code sample</h3> | ||
<pre><code><section> | ||
<h2 id="ex1">Example 1 - <code>wb.getId()</code> and ID conflicts</h2> | ||
<p>Demonstrates how <code>wb.getId()</code> reacts when hardcoded IDs conflict with its naming convention (anything starting with <code>wb-auto-</code>).</p> | ||
|
||
<section> | ||
<h3>Hardcoded IDs</h3> | ||
<ul> | ||
<li id="wb-auto-"><code>wb-auto-</code></li> | ||
<li id="wb-auto-3abc"><code>wb-auto-3abc</code></li> | ||
<li id="wb-auto-4."><code>wb-auto-4.</code></li> | ||
<li id="wb-auto-17"><code>wb-auto-17</code></li> | ||
<li id="wb-auto-5.0"><code>wb-auto-5.0</code></li> | ||
<li id="wb-auto-1"><code>wb-auto-1</code></li> | ||
<li id="wb-auto-6.1"><code>wb-auto-6.1</code></li> | ||
<li id="wb-auto-2"><code>wb-auto-2</code></li> | ||
<li id="wb-auto-abc9"><code>wb-auto-abc9</code></li> | ||
</ul> | ||
</section> | ||
|
||
<section> | ||
<h3>Tables plugin</h3> | ||
<p>This plugin calls <code>wb.getId()</code>.</p> | ||
<table class="wb-tables table"> | ||
<thead> | ||
<tr> | ||
<th>Rendering engine</th> | ||
<th>Browser</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>Blink</td> | ||
<td>Chromium</td> | ||
</tr> | ||
<tr> | ||
<td>Gecko</td> | ||
<td>Firefox</td> | ||
</tr> | ||
<tr> | ||
<td>WebKit</td> | ||
<td>Safari</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</section> | ||
</section></code></pre> | ||
</section> |
This file contains 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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
{ | ||
"title": "Base de la BOEW", | ||
"language": "en", | ||
"category": "Other", | ||
"description": "Exemples pratiques des méthodes natifs de la base de la BOEW.", | ||
"tag": "core", | ||
"parentdir": "core", | ||
"altLangPrefix": "core", | ||
"dateModified": "2024-07-02" | ||
} | ||
--- | ||
|
||
<div class="wb-prettify all-pre hide"></div> | ||
|
||
<p>{{description}}</p> | ||
|
||
<nav> | ||
<h2>Sur cette page</h2> | ||
<ul> | ||
<li><a href="#ex1">Exemple 1 - <code>wb.getId()</code> et conflits d’IDs</a></li> | ||
</ul> | ||
</nav> | ||
|
||
<section> | ||
<h2 id="ex1">Exemple 1 - <code>wb.getId()</code> et conflits d’IDs</h2> | ||
<p>Démontre comment <code>wb.getId()</code> réagit quand des IDs codés en dur entrent en conflit avec sa convention de nommage (tout ce qui commence par <code>wb-auto-</code>).</p> | ||
|
||
<section> | ||
<h3>IDs codés en dur</h3> | ||
<ul> | ||
<li id="wb-auto-"><code>wb-auto-</code></li> | ||
<li id="wb-auto-3abc"><code>wb-auto-3abc</code></li> | ||
<li id="wb-auto-4."><code>wb-auto-4.</code></li> | ||
<li id="wb-auto-17"><code>wb-auto-17</code></li> | ||
<li id="wb-auto-5.0"><code>wb-auto-5.0</code></li> | ||
<li id="wb-auto-1"><code>wb-auto-1</code></li> | ||
<li id="wb-auto-6.1"><code>wb-auto-6.1</code></li> | ||
<li id="wb-auto-2"><code>wb-auto-2</code></li> | ||
<li id="wb-auto-abc9"><code>wb-auto-abc9</code></li> | ||
</ul> | ||
</section> | ||
|
||
<section> | ||
<h3>Plugiciel de tableaux</h3> | ||
<p>This plugin calls <code>wb.getId()</code>.</p> | ||
<table class="wb-tables table"> | ||
<thead> | ||
<tr> | ||
<th>Moteur de rendu</th> | ||
<th>Navigateur</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>Blink</td> | ||
<td>Chromium</td> | ||
</tr> | ||
<tr> | ||
<td>Gecko</td> | ||
<td>Firefox</td> | ||
</tr> | ||
<tr> | ||
<td>WebKit</td> | ||
<td>Safari</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</section> | ||
|
||
<h3>Exemple de code</h3> | ||
<pre><code><section> | ||
<h2 id="ex1">Exemple 1 - <code>wb.getId()</code> et conflits d’IDs</h2> | ||
<p>Démontre comment <code>wb.getId()</code> réagit quand des IDs codés en dur entrent en conflit avec sa convention de nommage (tout ce qui commence par <code>wb-auto-</code>).</p> | ||
|
||
<section> | ||
<h3>IDs codés en dur</h3> | ||
<ul> | ||
<li id="wb-auto-"><code>wb-auto-</code></li> | ||
<li id="wb-auto-3abc"><code>wb-auto-3abc</code></li> | ||
<li id="wb-auto-4."><code>wb-auto-4.</code></li> | ||
<li id="wb-auto-17"><code>wb-auto-17</code></li> | ||
<li id="wb-auto-5.0"><code>wb-auto-5.0</code></li> | ||
<li id="wb-auto-1"><code>wb-auto-1</code></li> | ||
<li id="wb-auto-6.1"><code>wb-auto-6.1</code></li> | ||
<li id="wb-auto-2"><code>wb-auto-2</code></li> | ||
<li id="wb-auto-abc9"><code>wb-auto-abc9</code></li> | ||
</ul> | ||
</section> | ||
|
||
<section> | ||
<h3>Plugiciel de tableaux</h3> | ||
<p>This plugin calls <code>wb.getId()</code>.</p> | ||
<table class="wb-tables table"> | ||
<thead> | ||
<tr> | ||
<th>Moteur de rendu</th> | ||
<th>Navigateur</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>Blink</td> | ||
<td>Chromium</td> | ||
</tr> | ||
<tr> | ||
<td>Gecko</td> | ||
<td>Firefox</td> | ||
</tr> | ||
<tr> | ||
<td>WebKit</td> | ||
<td>Safari</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</section> | ||
</section></code></pre> | ||
</section> |