Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/js/components/slugs/Slug.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class Slug {
this.#controller = new AbortController;

let aborted = false;
return axios.post(cp_url('slug'), payload, { signal: this.#controller.signal })
return axios.post(cp_url('slug'), payload, { signal: this.#controller.signal, transformResponse: [(data) => data] })
.then(response => response.data)
.catch(e => {
if (axios.isCancel(e)) {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/slugs/Slugify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default {
handler() {
if (!this.shouldSlugify) {
this.slug = this.to;
} else if (!this.from) {
} else if (this.from === null || this.from === undefined || this.from === '') {
this.slug = '';
} else {
this.slugify();
Expand Down
6 changes: 4 additions & 2 deletions src/Fieldtypes/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ public function process($data)

public function preProcessIndex($value)
{
if ($value) {
return $this->config('prepend').$value.$this->config('append');
if (is_null($value)) {
return null;
}

return $this->config('prepend').$value.$this->config('append');
}
}
3 changes: 3 additions & 0 deletions tests/Feature/SlugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static function slugProvider()
'german characters' => ['Björn Müller', '-', 'de', 'bjoern-mueller'],
'arabic characters' => ['صباح الخير', '-', 'ar', 'sbah-alkhyr'],
'alternate separator' => ['one two three', '_', 'en', 'one_two_three'],
'null string' => ['null', '-', 'en', 'null'],
'zero string' => ['0', '-', 'en', '0'],
'false string' => ['false', '-', 'en', 'false'],
];
}
}
25 changes: 25 additions & 0 deletions tests/Fieldtypes/TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,29 @@ public static function processValuesProvider()
'number' => ['number', [0, 3, 3, 3.14, null]],
];
}

#[Test]
#[DataProvider('preProcessIndexProvider')]
public function it_pre_processes_index_values($config, $value, $expected)
{
$field = (new Text)->setField(new Field('test', array_merge([
'type' => 'text',
], $config)));

$this->assertSame($expected, $field->preProcessIndex($value));
}

public static function preProcessIndexProvider()
{
return [
'string value' => [[], 'hello', 'hello'],
'null value' => [[], null, null],
'zero integer' => [[], 0, '0'],
'zero string' => [[], '0', '0'],
'zero with prepend' => [['prepend' => '$'], 0, '$0'],
'zero with append' => [['append' => '%'], 0, '0%'],
'zero with prepend and append' => [['prepend' => '$', 'append' => '%'], 0, '$0%'],
'string with prepend' => [['prepend' => '$'], 'hello', '$hello'],
];
}
}