Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Array Indices #3

Closed
battis opened this issue Aug 17, 2015 · 2 comments
Closed

Array Indices #3

battis opened this issue Aug 17, 2015 · 2 comments
Assignees
Labels

Comments

@battis
Copy link
Member

battis commented Aug 17, 2015

It looks like Canvas is expecting URL parameters for arrays that do not include numerical indices. For example, Canvas would expect this:

http://canvas-instance.instructure.com/api/v1/courses/123/sections?include[]=students&include[]=enrollments

At the same time http_build_query() is trying to build legal URL parameters, which require that at least the base URL be indexed, resulting in shenanigans like this:

http://canvas-instance.instructure.com/api/v1/courses/123/sections?include%5B0%5D=students&include%5B1%5D=enrollments

It appears, at least, that Canvas tolerates URL-encoded arrays, but not the indices, so a request like this would work, allowing the result of http_build_query() to be post-processed as described here:

http://canvas-instance.instructure.com/api/v1/courses/123/sections?include%5B%5D=students&include%5B%5D=enrollments

Moreover, it appears that Pest calls Pest::prepData() for Pest::put() and Pest::post() only, essentially as a check to see if a file upload is included as part of the data parameters, but reconfiguring Pest::get() would require essentially overriding the entire method, as it embeds the http_build_query() call in the method, without calling Pest::prepData().

@battis battis added the bug label Aug 17, 2015
@battis battis self-assigned this Aug 17, 2015
battis added a commit to battis/pest that referenced this issue Aug 17, 2015
This seems like the kind of thing that one should never want to do. Unless... you're dealing with a RESTful API that doesn't seem to understand URL parameters that contain numeric indices for the base array. [For example](smtech/canvaspest#3):

Instructure Canvas is expecting URL parameters for arrays that do not include numerical indices:

```
http://canvas-instance.instructure.com/api/v1/courses/123/sections?include[]=students&include[]=enrollments
```

At the same time [`http_build_query()`](https://github.com/smtech/canvaspest/blob/9110d69f756ff49e8da687381eaee52a767c0389/CanvasPest.php#L108) is trying to build legal URL parameters, which require that at least the base URL be indexed, resulting in shenanigans like this:

```
http://canvas-instance.instructure.com/api/v1/courses/123/sections?include%5B0%5D=students&include%5B1%5D=enrollments
```

It appears, at least, that Canvas tolerates URL-encoded arrays, but not the indices, so a request like this would work, allowing the result of `http_build_query()` to be post-processed [as described here](http://php.net/manual/en/function.http-build-query.php#111819):

```
http://canvas-instance.instructure.com/api/v1/courses/123/sections?include%5B%5D=students&include%5B%5D=enrollments
```
battis pushed a commit that referenced this issue Aug 17, 2015
Override `http_build_query()` to format array parameters as Canvas prefers. (cf. [this issue](#3))
battis pushed a commit that referenced this issue Aug 17, 2015
Override `http_build_query()` to format array parameters as Canvas prefers. (cf. [this issue](#3))
battis added a commit to battis/pest that referenced this issue Aug 17, 2015
This seems like the kind of thing that one should never want to do. Unless... you're dealing with a RESTful API that doesn't seem to understand URL parameters that contain numeric indices for the base array. [For example](smtech/canvaspest#3):

Instructure Canvas is expecting URL parameters for arrays that do not include numerical indices:

```
http://canvas-instance.instructure.com/api/v1/courses/123/sections?include[]=students&include[]=enrollments
```

At the same time [`http_build_query()`](https://github.com/smtech/canvaspest/blob/9110d69f756ff49e8da687381eaee52a767c0389/CanvasPest.php#L108) is trying to build legal URL parameters, which require that at least the base URL be indexed, resulting in shenanigans like this:

```
http://canvas-instance.instructure.com/api/v1/courses/123/sections?include%5B0%5D=students&include%5B1%5D=enrollments
```

It appears, at least, that Canvas tolerates URL-encoded arrays, but not the indices, so a request like this would work, allowing the result of `http_build_query()` to be post-processed [as described here](http://php.net/manual/en/function.http-build-query.php#111819):

```
http://canvas-instance.instructure.com/api/v1/courses/123/sections?include%5B%5D=students&include%5B%5D=enrollments
```
battis added a commit to battis/pest that referenced this issue Aug 17, 2015
This seems like the kind of thing that one should never want to do. Unless... you're dealing with a RESTful API that doesn't seem to understand URL parameters that contain numeric indices for the base array. [For example](smtech/canvaspest#3):

Instructure Canvas is expecting URL parameters for arrays that do not include numerical indices:

```
http://canvas-instance.instructure.com/api/v1/courses/123/sections?include[]=students&include[]=enrollments
```

At the same time [`http_build_query()`](https://github.com/smtech/canvaspest/blob/9110d69f756ff49e8da687381eaee52a767c0389/CanvasPest.php#L108) is trying to build legal URL parameters, which require that at least the base URL be indexed, resulting in shenanigans like this:

```
http://canvas-instance.instructure.com/api/v1/courses/123/sections?include%5B0%5D=students&include%5B1%5D=enrollments
```

It appears, at least, that Canvas tolerates URL-encoded arrays, but not the indices, so a request like this would work, allowing the result of `http_build_query()` to be post-processed [as described here](http://php.net/manual/en/function.http-build-query.php#111819):

```
http://canvas-instance.instructure.com/api/v1/courses/123/sections?include%5B%5D=students&include%5B%5D=enrollments
```
@battis
Copy link
Member Author

battis commented Aug 17, 2015

Annoyingly, of course, the whole reason to write CanvasPest::prepData() was to do an end run around this issue. And it felt hacky at the time.

Perhaps the way to go is to override http_build_query(), ]which seems dicey](http://de.php.net/manual/en/function.override-function.php#50821).

@battis
Copy link
Member Author

battis commented Aug 17, 2015

Looks like the best way to go (for me) is to fork educoder/pest and allow overriding of http_build_query() by extending classes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant