Coder Social home page Coder Social logo

Comments (4)

schlagmichdoch avatar schlagmichdoch commented on June 11, 2024 1

I do not know what you mean. Please fill out the bug issue template and provide an example

from pairdrop.

ueen avatar ueen commented on June 11, 2024

Just send this link (invalid) and try to click on it on the receiving end ;)

https://onedrive.live.com/?authkey=%dfdsssdf7LJSM3w&id=88ADFF5%21285&cid=2DC78C46388A4354

What happens is exactly what i described in the title, only https://onedrive.live.com/?authkey= is opened

from pairdrop.

ueen avatar ueen commented on June 11, 2024

ok lets fix it :))

maybe this?
https://www.freecodecamp.org/news/how-to-validate-urls-in-javascript/

try {
   let url = new URL(message);
    //set as link
} catch (err) {
    //set as text
}

btw love the new design, also it seems to work more stable than before <3

from pairdrop.

schlagmichdoch avatar schlagmichdoch commented on June 11, 2024

The following comments were deleted by GitHub (via hubot) as part of mistakenly marking this account as spam on 17th February 2024. The correct thread order and the creation date is unclear. I decided to manually restore them anyway in order to complete the information this issue holds even though the restored information might be outdated:

Comment by @schlagmichdoch:

Thanks for the example!

Your title leaves multiple options:

  • Sending links via send message dialog does not work properly
  • Sending links via Android Share Menu does not work properly
  • Sending links via iOS shortcut does not work properly
  • Sending links via CLI does not work properly
  • etc.
  • Sending links does work properly but the links are not correctly converted to clickable links (the actual case)

Adding some general information and a step by step guide how to reproduce the issue makes it much easier to determine whats wrong. This repo is quite easy to maintain but on other repos you might not have gotten an answer in the first place.

This is an issue though. I did some testing:
This message:

www.test
www.test.com
https://test.com
http://test.com
https://test.com?auth=token&si=123
https://onedrive.live.com/?authkey=%dfdsssdf7LJSM3w&id=88ADFF5%21285&cid=2DC78C46388A4354

is converted to this html:

<a href="www.test" target="_blank">www.test</a><br>
<a href="www.test.com" target="_blank">www.test.com</a><br>
<a href="https://test.com" target="_blank">https://test.com</a><br>
<a href="http://test.com" target="_blank">http://test.com</a><br>
<a href="https://test.com?auth=token&amp;si=123" target="_blank">https://test.com?auth=token&amp;si=123</a><br>
<a href="https://onedrive.live.com/?authkey=" target="_blank">https://onedrive.live.com/?authkey=</a>%dfdsssdf7LJSM3w&amp;id=88ADFF5%21285&amp;cid=2DC78C46388A4354

Apparently, the URL replacement does not stop at the equal sign but at the percentage sign.
Also, www.test.com should be replaced with http:/www.test.com to prevent pointing https://pairdrop.net/www.test.com to and www.test should not be a URL at all.

Comment by @schlagmichdoch:

maybe this? https://www.freecodecamp.org/news/how-to-validate-urls-in-javascript/

try {
   let url = new URL(message);
    //set as link
} catch (err) {
    //set as text
}

Not quite, as we don’t know yet where possible URLs are positioned. Instead, I used a REGEX substitution for this and enhanced it to fix this issue.
See

PairDrop/public/scripts/ui.js

Lines 2018 to 2033 in ccb2170

// Beautify text if text is short
if (text.length < 2000) {
// replace URLs with actual links
this.$text.innerHTML = this.$text.innerHTML
.replace(/(^|(?<=(<br>|\s)))(https?:\/\/|www.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%]){2,}\.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%.]){2,})/g,
(url) => {
let link = url;
// prefix www.example.com with http protocol to prevent it from being a relative link
if (link.startsWith('www')) {
link = "http://" + link
}
return `<a href="${link}" target="_blank">${url}</a>`;
});
}

from pairdrop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.