Skip to content
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

Without url encode in generate #58

Closed
harikt opened this issue Aug 5, 2014 · 12 comments
Closed

Without url encode in generate #58

harikt opened this issue Aug 5, 2014 · 12 comments

Comments

@harikt
Copy link
Member

harikt commented Aug 5, 2014

Is it possible to create urls without urlencode ?

Eg : in aura/asset-bundle when we pass the file path as /css/something.css all will be converted to %2Fcss%2Fsomething.css . That means even when we have the real path with some sort of file moved, the css may not get loaded.

Any idea to fix for routes like that ?

@harikt harikt changed the title Without raw url encode in generate Without url encode in generate Aug 5, 2014
@pmjones
Copy link
Member

pmjones commented Aug 25, 2014

That's an interesting issue. I assume it's because the value itself includes slashes (e.g., "path" => "/css/something.css"). The question then is, does it cause trouble later on, or does it just look ugly?

@harikt
Copy link
Member Author

harikt commented Aug 25, 2014

The url will be %2Fcss%2Fsomething.css which when read via the assets will not work. We may need to do urldecode in the asset bundle.

@pmjones
Copy link
Member

pmjones commented Aug 25, 2014

We may need to do urldecode in the asset bundle.

/me nods

Alternatively, do we want to change %2F back to / when doing url encode in the router? I don't know if that's a good idea or not.

@harikt
Copy link
Member Author

harikt commented Aug 25, 2014

The problem is

<link rel="stylesheet" href="<?php echo $this->router()
      ->generate('aura.asset',
          array(
              'vendor' => 'cocoframework',
              'package' => 'example',
              'file' => '/css/poole.css'
          )
      ); ?>">

http://cocoframework.localhost/asset/cocoframework/example/%2Fcss%2Fpoole.css when requested in browser gives a 404 .

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /asset/cocoframework/example//css/poole.css was not found on this server.</p>
<hr>
<address>Apache/2.2.22 (Ubuntu) Server at cocoframework.localhost Port 80</address>
</body></html>

Alternatively, do we want to change %22 back to / when doing url encode in the router? I don't know if that's a good idea or not.

I don't know what you were looking for :( .

Taking the route from https://github.com/harikt/Aura.Asset_Bundle/blob/master/config/Common.php#L28-L34

 $router->add('aura.asset', '/asset/{vendor}/{package}/{file}')
->setValues([
'action' => 'aura.asset',
])
->addTokens(array(
'file' => '(.*)'
));

@pmjones
Copy link
Member

pmjones commented Aug 25, 2014

Yeah, so what I'm saying is that maybe we should ...

  1. Apply urlencode() like we do already, and then
  2. str_replace('%2F', '/', $value)

... then replace the token with that value. The idea is that we url encode everything except slashes.

(An alternative would be to explode the value on slashes, url encode each piece, then implode with slashes.)

Does that make sense?

@harikt
Copy link
Member Author

harikt commented Aug 25, 2014

Got it. Not sure whether it is right / wrong. But it will work I guess :) .

@pmjones
Copy link
Member

pmjones commented Aug 25, 2014

Hey, can you send me the route code you are using to point to the asset bundle? I want to try some stuff out.

@pmjones
Copy link
Member

pmjones commented Aug 25, 2014

@harikt
Copy link
Member Author

harikt commented Aug 26, 2014

@pmjones yes. That is the route code. Nothing more.

@harikt
Copy link
Member Author

harikt commented Aug 26, 2014

@pmjones can we move the asset bundle to @auraphp organization ?

Edit : may be name it as Aura.AssetBundle ?

@pmjones
Copy link
Member

pmjones commented Aug 26, 2014

OK, @harikt , check out the new genraw branch. The generate() method now takes an optional third param, an array of keys to be left raw.

https://github.com/auraphp/Aura.Router/blob/genraw/src/Generator.php#L44-L58

So you could call generate('route.name', array('file' => 'styles/blog.css'), array('file')) to prevent encoding of the file value.

It's kind of hackish, so I'm open to other ideas.

@pmjones
Copy link
Member

pmjones commented Aug 29, 2014

Closed per the new generateRaw() method. Thanks @harikt for talking this out with me.

@pmjones pmjones closed this as completed Aug 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants