Skip to content

Commit af7b934

Browse files
Merge pull request #547 from MasoniteFramework/fix/544
added list defaults when using [] in inputs
2 parents fff793c + 0103304 commit af7b934

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

src/masonite/input/InputBag.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ def parse(self, environ):
9999
)
100100

101101
def get(self, name, default=None, clean=True, quote=True):
102+
if isinstance(name, str) and name.endswith("[]"):
103+
default = []
104+
102105
input = data_get(self.all(), name, default)
103106

104107
if isinstance(input, (str,)):

tests/core/request/test_input.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ def test_all_with_values(self):
4545
"""
4646
self.assertEqual(bag.all_as_values(), {"hello": "you"})
4747

48+
def test_can_get_defaults(self):
49+
bag = InputBag()
50+
bag.load({"QUERY_STRING": ""})
51+
self.assertEqual(bag.get("hello", "default"), "default")
52+
self.assertEqual(bag.get("hello"), None) #TODO: This should probably return a blank string instead of None
53+
self.assertEqual(bag.get("hello[]"), [])
54+
4855
def test_all_without_internal_values(self):
4956
bag = InputBag()
5057
bag.load({"QUERY_STRING": "hello=you&__token=tok"})

tests/features/scheduling/test_scheduling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pendulum
2-
from masonite.tests import TestCase
2+
from src.masonite.tests import TestCase
33
from src.masonite.scheduling import Task
44

55

tests/integrations/tasks/TaskTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Task Module Description"""
2-
from masonite.scheduling import Task
2+
from src.masonite.scheduling import Task
33

44

55
class TaskTest(Task):

0 commit comments

Comments
 (0)