Skip to content

Commit 8e6db1c

Browse files
authored
Merge pull request #76 from phiHero/patch
fix: URI encode user-inputted string
2 parents 9f33382 + b7324f6 commit 8e6db1c

19 files changed

+40
-22
lines changed

src/Alias.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(string $name, ApiCall $apiCall)
4141
*/
4242
public function endPointPath(): string
4343
{
44-
return sprintf('%s/%s', Aliases::RESOURCE_PATH, $this->name);
44+
return sprintf('%s/%s', Aliases::RESOURCE_PATH, encodeURIComponent($this->name));
4545
}
4646

4747
/**

src/Aliases.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(ApiCall $apiCall)
4343
*/
4444
public function endPointPath(string $aliasName): string
4545
{
46-
return sprintf('%s/%s', static::RESOURCE_PATH, $aliasName);
46+
return sprintf('%s/%s', static::RESOURCE_PATH, encodeURIComponent($aliasName));
4747
}
4848

4949
/**

src/AnalyticsRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public function delete()
2525

2626
private function endpointPath()
2727
{
28-
return AnalyticsRules::RESOURCE_PATH . '/' . $this->ruleName;
28+
return AnalyticsRules::RESOURCE_PATH . '/' . encodeURIComponent($this->ruleName);
2929
}
3030
}

src/AnalyticsRules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public function retrieve()
3434

3535
private function endpoint_path($operation = null)
3636
{
37-
return self::RESOURCE_PATH . ($operation === null ? '' : "/$operation");
37+
return self::RESOURCE_PATH . ($operation === null ? '' : "/" . encodeURIComponent($operation));
3838
}
3939
}

src/Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Typesense\Exceptions\ConfigError;
66
use Typesense\Lib\Configuration;
77

8+
include('utils/utils.php');
89
/**
910
* Class Client
1011
*

src/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct(string $name, ApiCall $apiCall)
6464
*/
6565
public function endPointPath(): string
6666
{
67-
return sprintf('%s/%s', Collections::RESOURCE_PATH, $this->name);
67+
return sprintf('%s/%s', Collections::RESOURCE_PATH, encodeURIComponent($this->name));
6868
}
6969

7070
/**

src/Conversation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ public function delete(): array
6868
*/
6969
public function endPointPath(): string
7070
{
71-
return sprintf('%s/%s', Conversations::RESOURCE_PATH, $this->id);
71+
return sprintf('%s/%s', Conversations::RESOURCE_PATH, encodeURIComponent($this->id));
7272
}
7373
}

src/ConversationModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ public function delete(): array
6868
*/
6969
public function endPointPath(): string
7070
{
71-
return sprintf('%s/%s', ConversationModels::RESOURCE_PATH, $this->id);
71+
return sprintf('%s/%s', ConversationModels::RESOURCE_PATH, encodeURIComponent($this->id));
7272
}
7373
}

src/Document.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ private function endpointPath(): string
5151
return sprintf(
5252
'%s/%s/%s/%s',
5353
Collections::RESOURCE_PATH,
54-
$this->collectionName,
54+
encodeURIComponent($this->collectionName),
5555
Documents::RESOURCE_PATH,
56-
$this->documentId
56+
encodeURIComponent($this->documentId)
5757
);
5858
}
5959

src/Documents.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private function endPointPath(string $action = ''): string
5353
return sprintf(
5454
'%s/%s/%s/%s',
5555
Collections::RESOURCE_PATH,
56-
$this->collectionName,
56+
encodeURIComponent($this->collectionName),
5757
static::RESOURCE_PATH,
5858
$action
5959
);
@@ -125,7 +125,7 @@ public function createMany(array $documents, array $options = []): array
125125
{
126126
$this->apiCall->getLogger()->warning(
127127
"createMany is deprecated and will be removed in a future version. " .
128-
"Use import instead, which now takes both an array of documents or a JSONL string of documents"
128+
"Use import instead, which now takes both an array of documents or a JSONL string of documents"
129129
);
130130
return $this->import($documents, $options);
131131
}

0 commit comments

Comments
 (0)