Hi, Thanks for such a nice module.
I have one problem in Remote URL attachment module.

When i have the filename with space i.e http://www.mysourcefiledomain.com/file name.docx at that time it doesn't allow to attatch the file.
Here there is space between file and name

It is working fine when there is no space between the words of file name http://www.mysourcefiledomain.com/filename.docx

Comments

joelrotelli’s picture

One solution could be to allow spaces in the valid_url function but i'm not sure whether very secure

However, we can just allow spaces in the query on the filefield_source_remote_value function, but i'm not sure too whether a good way ?

mohit_aghera’s picture

But we can not modify valid_url function as it is drupal core function. But how should i modify the code of valid_url function to allow the space

function valid_url($url, $absolute = FALSE) {
  if ($absolute) {
    return (bool)preg_match("
      /^                                                      # Start at the beginning of the text
      (?:ftp|https?|feed):\/\/                                # Look for ftp, http, https or feed schemes
      (?:                                                     # Userinfo (optional) which is typically
        (?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)*      # a username or a username and password
        (?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@          # combination
      )?
      (?:
        (?:[a-z0-9\-\.]|%[0-9a-f]{2})+                        # A domain name or a IPv4 address
        |(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\])         # or a well formed IPv6 address
      )
      (?::[0-9]+)?                                            # Server port number (optional)
      (?:[\/|\?]
        (?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})   # The path and query (optional)
      *)?
    $/xi", $url);
  }
  else {
    return (bool)preg_match("/^(?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})+$/i", $url);
  }
}

I will create my own function with modified code. Can you guide me how to modify code it so i can allow some space in url.

joelrotelli’s picture

Yes we could make a patch for that but I don't think it's a good idea to allow spaces in URL

mohit_aghera’s picture

But today while attaching the file many file contains the space in between the name, so how can we achieve it ? Do you have any idea.

Can we encode it using urlencode ?

joelrotelli’s picture

I have tried with urlencode but it's not working anymore

I have also tried by removing temporarly the valid_url function but when the extension is checked, it fails because of the space in the name...

quicksketch’s picture

Title: Filefield source "Remote URL" doesn't upload file when there is space in the file name » Accomodate for spaces when using the "Remote URL" option
Category: bug » feature

So spaces in URLs are not allowed by the URL spec (see http://www.w3schools.com/tags/ref_urlencode.asp for a simple reference). A URL like http://www.mysourcefiledomain.com/file name.docx should actually be http://www.mysourcefiledomain.com/file%20name.docx. Most browsers will accomodate for the spaces and convert them to URL-encoded entities for you.

To make FileField Sources work with spaces, what would need to be done is before the value is attempted to be used, it should automatically adjust the URL to urlencode it before checking if it's a valid URL. However you can't just run urlencode() on the whole URL, otherwise things like the :// in http:// get encoded also. We'd have to urlencode each individual part of the path. I think this would also need to detect if a URL was already URL encoded, otherwise if a valid, already-encoded URL was entered, we wouldn't want to double-encode it.

quicksketch’s picture

Issue summary: View changes

Added link in the url