Skip to content

Commit

Permalink
chore: new CSS absolute changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Apr 12, 2024
1 parent 5de1153 commit 7b8b2a0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/appier/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
""" The second regular expression that is going to be used
by the slugier sub system to replace some of its values """

CSS_ABS_REGEX = re.compile(b"url\((?!(http:\/\/|https:\/\/|\/\/|\/))([^\)]+)\)")
CSS_ABS_REGEX = re.compile(rb"url\((?!(http:\/\/|https:\/\/|\/\/|\/))([^\)]+)\)")
""" The regular expression that is going to be used to capture
the relative CSS URL values, so that they may be converted into
absolute ones for proper inlining, note that the regex is defined
Expand Down Expand Up @@ -3763,8 +3763,8 @@ def dump_url(
timeout = int(max_age)

# in case the type of the resource is css an extra replace operation
# on the urls must be performed so that the base URL is added to all
# the resources, this is required so that relative urls are fixed
# on the URLs must be performed so that the base URL is added to all
# the resources, this is required so that relative URLs are fixed
if type == "css":
base, _name = url.rsplit("/", 1)
base = legacy.bytes(base)
Expand Down
16 changes: 16 additions & 0 deletions src/appier/test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,19 @@ def test_locale_filter(self):
self.assertEqual(result, appier.legacy.u("olá"))
result = self.app.template(template, locale="en_us")
self.assertEqual(result, appier.legacy.u("hello"))

def test_css_abs(self):
result = appier.base.CSS_ABS_REGEX.sub(
b"url(http://www.example/\\2)", b"url(image.jpg)"
)
self.assertEqual(result, b"url(http://www.example/image.jpg)")

result = appier.base.CSS_ABS_REGEX.sub(
b"url(https://www.example/\\2)", b"url(image.jpg)"
)
self.assertEqual(result, b"url(https://www.example/image.jpg)")

result = appier.base.CSS_ABS_REGEX.sub(
b"url(http://www.example/\\2)", b"url(https://example.com/image.jpg)"
)
self.assertEqual(result, b"url(https://example.com/image.jpg)")
43 changes: 43 additions & 0 deletions src/appier/test/validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Hive Appier Framework
# Copyright (c) 2008-2024 Hive Solutions Lda.
#
# This file is part of Hive Appier Framework.
#
# Hive Appier Framework is free software: you can redistribute it and/or modify
# it under the terms of the Apache License as published by the Apache
# Foundation, either version 2.0 of the License, or (at your option) any
# later version.
#
# Hive Appier Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# Apache License for more details.
#
# You should have received a copy of the Apache License along with
# Hive Appier Framework. If not, see <http://www.apache.org/licenses/>.

__author__ = "João Magalhães <joamag@hive.pt>"
""" The author(s) of the module """

__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
""" The license for the module """

import unittest

import appier


class ValidationTest(unittest.TestCase):

def test_is_email(self):
appier.is_email("user@domain.com", True)
appier.is_email("user", False)
appier.is_email("domain.com", False)
appier.is_email("first.second@domain.com", True)
appier.is_email("first+second@domain.com", True)

0 comments on commit 7b8b2a0

Please sign in to comment.