Skip to content

Commit 6b435c7

Browse files
authored
🔀 Merge pull request #83 from astariul/fix_version_comparison
Fix version comparison
2 parents 43e0b8c + d10137f commit 6b435c7

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

‎static/package_page.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ function load_readme(version, scroll_to_div=false){
3232
});
3333
}
3434

35+
function put_readme(version, markupContent, scroll_to_div=false){
36+
addDynamicClickDelegation(`${version}`);
37+
38+
const contentDivs = document.querySelectorAll('.versions div');
39+
contentDivs.forEach(div => div.classList.remove('selected'));
40+
41+
document.getElementById(version).classList.add('selected');
42+
document.getElementById('markdown-container').innerHTML = marked.parse(markupContent);
43+
if (scroll_to_div) {
44+
// document.getElementById('description_pkg').scrollIntoView();
45+
history.replaceState(null, null, '#'+version);
46+
}
47+
}
48+
3549
function warn_unsafe() {
3650
document.getElementById('installdanger').hidden = false;
3751
document.getElementById('installcmd').hidden = true;

‎static/pypi_checker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
function semverCompare(a, b) {
2+
// Remove leading letters, such as `v` (`v4.23` becomes `4.23`)
3+
const clean = (v) => v.replace(/^[a-zA-Z]+/, "");
4+
a = clean(a);
5+
b = clean(b);
6+
7+
// Actual comparison
28
if (a.startsWith(b + "-")) return -1
39
if (b.startsWith(a + "-")) return 1
410
return a.localeCompare(b, undefined, { numeric: true, sensitivity: "case", caseFirst: "upper" })

‎transformers/index.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,12 @@ <h6 class="text-header">
9898
</div>
9999

100100
<script>
101-
var url_readme_main = 'https://raw.githubusercontent.com/huggingface/transformers/main/README.md';
102-
103101
$(document).ready(function () {
104102
var this_vers = document.getElementById('latest-main-version').textContent.trim();
105103
document.getElementById(this_vers).classList.add('main');
106104
check_supply_chain_attack("transformers", this_vers, warn_unsafe);
107-
108-
if (window.location.hash != "") {
109-
let version_hash = window.location.hash;
110-
version = version_hash.replace('#', '');
111-
load_readme(version, scroll_to_div=true);
112-
return;
113-
}
114-
load_readme(this_vers);
105+
106+
put_readme(this_vers, "This is a (safe) example of a package vulnerable to supply chain attacks. Here we registered a private package called `transformers`. But another package with the exact same name and a higher version is registered in the public PyPi index. Running the install command would install the package registered there (which might be malicious), not my private package as intended. If that's the case, a warning is displayed in this page.");
115107
});
116108
</script>
117109
</body>

0 commit comments

Comments
 (0)