Repository navigation
fix(landscape): accept links typed without https in the add form #822
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -218,18 +218,35 @@ | |||||
| return errors; | ||||||
| } | ||||||
|
|
||||||
| function normalizeUrl(value) { | ||||||
| var text = String(value || '').trim(); | ||||||
| if (!text) return ''; | ||||||
| if (/^http:\/\//i.test(text)) return 'https://' + text.slice(7); | ||||||
| if (/^https:/i.test(text)) return text; | ||||||
| if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(text)) return 'https://' + text.replace(/^\/+/, ''); | ||||||
| return text; | ||||||
| } | ||||||
|
|
||||||
| function normalizeRepo(value) { | ||||||
| var text = normalizeUrl(value).replace(/[?#].*$/, '').replace(/^https:\/\/www\./i, 'https://'); | ||||||
| var page = /^(https:\/\/(?:github\.com|codeberg\.org)\/[^\/]+\/[^\/]+)\/(?:tree|blob|issues|pulls?|releases|wiki|actions|src|commits?)(?:\/.*)?$/i.exec(text); | ||||||
|
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. 🟡 GitHub Tags links block submissions When a contributor enters
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||
| if (page) text = page[1]; | ||||||
| text = text.replace(/^(https:\/\/gitlab\.com\/.+?)\/-\/.*$/i, '$1'); | ||||||
| return text.replace(/\/+$/, '').replace(/\.git$/, ''); | ||||||
| } | ||||||
|
|
||||||
| function buildEntry(form) { | ||||||
| var entry = { | ||||||
| name: String(form.name || '').trim(), | ||||||
| url: String(form.url || '').trim(), | ||||||
| url: normalizeUrl(form.url), | ||||||
| category: String(form.category || ''), | ||||||
| description: String(form.description || '').trim(), | ||||||
| open_source: Boolean(form.open_source) | ||||||
| }; | ||||||
| if (entry.open_source) entry.repo = String(form.repo || '').trim().replace(/\/+$/, '').replace(/\.git$/, ''); | ||||||
| if (entry.open_source) entry.repo = normalizeRepo(form.repo); | ||||||
| var handle = String(form.x || '').trim().replace(/^@/, '').replace(/^https?:\/\/(www\.)?(x|twitter)\.com\//i, '').replace(/\/+$/, ''); | ||||||
| if (handle) entry.x = handle; | ||||||
| entry.logo_url = String(form.logo_url || '').trim(); | ||||||
| entry.logo_url = normalizeUrl(form.logo_url); | ||||||
| return entry; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -414,14 +414,21 @@ | |||||||
| }; | ||||||||
| } | ||||||||
|
|
||||||||
| var FORM_LABELS = { name: 'Tool name', url: 'Website', category: 'Category', description: 'Description', repo: 'Source repository', logo_url: 'Link to your logo', x: 'X account' }; | ||||||||
|
|
||||||||
| function formProblem(problem) { | ||||||||
| if (/^give "logo_url"/.test(problem)) return 'Link to your logo is required'; | ||||||||
| return problem.replace(/^"([a-z_]+)"/, function (match, field) { return FORM_LABELS[field] || match; }); | ||||||||
| } | ||||||||
|
|
||||||||
| function updateForm() { | ||||||||
| var form = document.getElementById('addForm'); | ||||||||
| if (!form || !rules) return; | ||||||||
| var values = formValues(); | ||||||||
| var entry = rules.buildEntry(values); | ||||||||
| var slug = rules.slugify(entry.name); | ||||||||
| var categoryIds = data.categories.map(function (category) { return category.id; }); | ||||||||
| var errors = slug ? rules.validateEntry(slug, entry, categoryIds) : ['"name" is required']; | ||||||||
| var errors = rules.validateEntry(slug || 'your-tool', entry, categoryIds); | ||||||||
|
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. 🔴 Empty filename for non-Latin names When a nonempty tool name yields no slug,
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. 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. Reject names that produce an empty slug. If an otherwise valid submission has the name Keep full validation for blank names. Add an error when a nonempty name produces an empty slug. Add a regression test that checks the button stays disabled for this case.
|
||||||||
| var taken = data.entries.some(function (existing) { return existing.slug === slug; }); | ||||||||
| if (taken) errors.unshift('"' + entry.name + '" is already listed. Open its file on GitHub to change it.'); | ||||||||
|
|
||||||||
|
|
@@ -433,7 +440,9 @@ | |||||||
| var touched = form.getAttribute('data-touched') === 'true'; | ||||||||
| var list = document.getElementById('addErrors'); | ||||||||
| list.textContent = ''; | ||||||||
| if (touched) errors.forEach(function (problem) { list.appendChild(el('li', '', problem)); }); | ||||||||
| if (touched) errors.forEach(function (problem) { list.appendChild(el('li', '', formProblem(problem))); }); | ||||||||
| var status = document.getElementById('addStatus'); | ||||||||
| if (status) status.textContent = errors.length ? 'The button turns on when the form has no problems. ' + errors.length + ' left.' : 'Ready. GitHub opens in a new tab.'; | ||||||||
|
rohitg00 marked this conversation as resolved.
Resolved
rohitg00 marked this conversation as resolved.
Resolved
|
||||||||
|
|
||||||||
| var submit = document.getElementById('addSubmit'); | ||||||||
| var ready = errors.length === 0; | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.