django-storage url missing backslash - django-cms

I have a problem with some image source urls. For example I have
<img src="https://url_to_my_bucket/adminimg/icon_calendar.gif" alt="Kalender"/>
This code is generated from the django-cms. Fore some reason, there is a '/' missing between the 'admin' and 'img'.
I set the AWS_QUERYSTRING_AUTH = False. If I don't use my s3 bucket everything works fine.
Any ideas, why this '/' is missing?

Related

ASP.NET Core URL Parameter Decoding

I have an ASP.NET Core web API and an issue with encoded URL's in query parameters.
I have an URL parameter like 'path/to/'. The IDENTIFIER part is something like 'HÄÄ/20/19'. This is urlEncoded in frontend to a link URL. The result is a link like
domain.com/new/stuff/path/to/H%C3%84%C3%84%2F20%2F19
Now, at some point, user gets redirected to a controller where this URL is used in a query parameter like:
param=%2Fpath%2Fto%2FH%C3%84%C3%84%2F20%2F19
I'm using request query to get the param
var param = HttpContext.Request.Query["param"].ToString();
After this the value of param is
%2Fpath%2Fto%2FHÄÄ%2F20%2F19
So the LATIN CAPITAL LETTER A WITH DIAERESIS are automatically decoded as the other encoded characters are not.
The actual problem comes when I'm redirecting the user to this URL. It ends up with a referer header where it causes havoc with an error message
System.InvalidOperationException: Invalid non-ASCII or control character in header: 0x00C4
I tried to just replace all the 'Ä' characters with 'A' and the problem is fixed. This is not a real fix though. I cannot encode the whole variable (see above) as it would result in double encoding for other encoded characters.
This problem only occurs with IE11 and Edge (AFAIK) and works fine with at least Chrome.
I'm not 100% sure where the actual problem is and why this is happening so does anyone have any ideas where to start looking and how to fix this without hacking with the string.replace?
EDIT
I could fix it with something like this, but I'm not seriously doing this. Seems way too hacky.
var problemPart = param.Substring(param.LastIndexOf('/') + 1, param.Length - param.LastIndexOf('/') - 1);
var fixedPart = WebUtility.UrlDecode(problemPart);
fixedPart = WebUtility.UrlEncode(fixedPart);
param = param.Replace(problemPart, fixedPart);
EDIT 2
I think the problem is that IE11 and Edge change the encoding by adding control characters to it when the URL ends up to the referer header. The fix I added to the original post doesn't actually fix the problem but just work around it. The control character that gets added to the URL is %C2%84 (so Ä becomes %C3%84%C2%84 instead of just %C3%84)
TEMPORARY WORKAROUND
I basically used the code above to workaround the issue. I iterated the parameter value and re-encoded all the invalid characters in it. This doesn't fix the root cause but works around the issue and user doesn't get any errors to the screen.

Get the host name from url without www or extension in asp.net

Hello i need a way to find out the host part of an url , i've tried
Request.Url.Host.Split('.')
but it doesn't work with url like this:
sub.sub.domain.com
or
www.domain.co.uk
since you can have a variable number of dots before and after the domain
i need to get only "domain"
Check out the second answer at Get just the domain name from a URL?
I checked the pastebin link; it's active. I didn't test the code myself, but if it outputs as he describes, you can .split() from there.
If you need to be totally flexibel, you need to make a list of all possible top-level-domains, and try to remove those, with dot, from the end of your string, resulting in
www.domain
or
sub.sub.domain
Then take the last characters after the last dot.

Drupal 7 path_save with a query arguments

I've searched all over for examples of this, but I haven't found any. I'm trying to create an alias for path which includes query arguments, like profile?arg1=113.
It doesn't matter if I provide path_save() with the plain string representation of the path, or if I provide it with url().
url('profile', array('query' => array('arg1' => $uid)))
Either way, ? and = show up as escaped characters on the URL aliases admin page, which naturally means the path can't be found.
How can I keep the ? and = from being escaped?
12/19/12 Edit 1: the larger context is that I'm trying to set up the alias when a Profile2 profile is being saved (i.e., in mymodule_profile2_presave()) - that's when I'll have all the information I need to programmatically set up the alias.
12/19/12 Edit 2: I just realized that the problem isn't on the insert side - the url_alias table actually has unescaped characters in it. The problem is that Drupal doesn't urldecode the path before using it...
12/20/12 Edit 3: Found a solution using Redirect instead of path aliases. Redirect properly decodes the query string!
You cannot attach the query string to the destination of an alias. The code executed from drupal_path_initialize() doesn't handle the query string correctly.
The function contains the following code.
$_GET['q'] = drupal_get_normal_path($_GET['q']);
Suppose that you have "example" as path alias that points to "node/93?uid=1"; that code would set $_GET['q'] to 'node/93?uid=1', while you are expecting $_GET['q'] to get 'node/93', and $_GET['uid'] to be set to 1.
What you could do is implementing hook_inbound_alter() with code similar to the following one.
function mymodule_url_inbound_alter(&$path, $original_path, $path_language) {
list ($path, $query) = explode('?', $path);
$_GET += drupal_get_query_array($query);
}

Problem in URL validation using ASP.Net Regular Expression Validator

I'm trying to use the ASP.Net Regular Expression Validator to validate a URL field. URL is www.tachibana.co.jp/tokyosys.htm. Validation expression used is ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?" but this is not working. Is there anything wrong with the Regular expression or URL ?
Rules are as below.
It should validate even if (http or
https) is included or not.
It should also trim the URL before
validating.
It should also validate the sub
domain URL's
It should also validate the URL's to
a file on domain or sub domain.
thanks
The problem is that your regex
http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
expects the URL to start with http:// or https://. Also, the dash inside the character class is misplaced.
Edit: Now that you've posted your rules, I suggest this:
^\s*((?:https?://)?(?:[\w-]+\.)+[\w-]+)(/[\w ./?%&=-]*)?\s*$
After a successful match, group 1 will contain the domain, and group 2 will contain the file path, if present.
^(?i)(http|ftp|https)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$
"(http(s)?://)?([\www]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?"
var re = /(http(s)?:\\)?([\w-]+\.)+[\w-]+[.com|.in|.org]+(\[\?%&=]*)?/
if (re.test(txt)) {
alert('Valid URL')
}
you can add domain needed in the last field of com,in,org

Why does a percent symbol in a get request break my site?

I feel pretty stupid for asking this, but I'm doing a form where the user enters some input and sometimes the input is a percent symbol, say 5%. When this gets passed along as part of a GET request, like this:
http://kburke.org/project/company_x/?id=4&var1=1&ops=23255&cashflow=25000&growth=5%25&pv=100000&roe=20&profitmargin=30&roe=80&turnover=2
I get a 404 Page Not Found error. When I remove the query string pair
&growth=5%25
the page loads fine. Can someone help explain what the problem is?
Edit: I tried removing all of the Javascript from the page and the server still craps out. I also just tried running it in MAMP as
http://localhost:8888/project/company_x/?id=4&var1=1&ops=23255&cashflow=25000&growth=5%25&pv=100000&roe=20&profitmargin=30&roe=80&turnover=2
and it worked fine. I'm wondering if it's a problem with my own server. When I open Firebug to the console and run the page, I see an error very briefly and then the 404 page loads - is there a way I can pause the redirect so I can read the error message?
Check out URL ENCODING. The "%" character in a url means something special.
You encode the space character ' ' as %20 in a url.
You encode the percent character '%' as %25 in a url.
So after your url gets to the script, your argument 'growth' will equal "5%".
I tried messing around with your url and it appears that your script is crashing when it tries to parse the growth argument, and your web site is hiding that crash from you by sending you to the 404 page. I'd post your script code if you need more help.

Resources