We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
CSS bundles generation breaks background images relative urls
This is a bug related to PR #1300.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `Products/CMFPlone/resources/browser/combine.py`
Content:
```
1 from zExceptions import NotFound
2 from Acquisition import aq_base
3 from datetime import datetime
4 from plone.registry.interfaces import IRegistry
5 from plone.resource.file import FilesystemFile
6 from plone.resource.interfaces import IResourceDirectory
7 from Products.CMFPlone.interfaces import IBundleRegistry
8 from Products.CMFPlone.interfaces.resources import (
9     OVERRIDE_RESOURCE_DIRECTORY_NAME,
10 )
11 from StringIO import StringIO
12 from zope.component import getUtility
13 from zope.component import queryUtility
14 
15 PRODUCTION_RESOURCE_DIRECTORY = "production"
16 
17 
18 def get_production_resource_directory():
19     persistent_directory = queryUtility(IResourceDirectory, name="persistent")
20     if persistent_directory is None:
21         return ''
22     container = persistent_directory[OVERRIDE_RESOURCE_DIRECTORY_NAME]
23     try:
24         production_folder = container[PRODUCTION_RESOURCE_DIRECTORY]
25     except NotFound:
26         return "%s/++unique++1" % PRODUCTION_RESOURCE_DIRECTORY
27     timestamp = production_folder.readFile('timestamp.txt')
28     return "%s/++unique++%s" % (
29         PRODUCTION_RESOURCE_DIRECTORY, timestamp)
30 
31 
32 def get_resource(context, path):
33     resource = context.unrestrictedTraverse(path)
34     if isinstance(resource, FilesystemFile):
35         (directory, sep, filename) = path.rpartition('/')
36         return context.unrestrictedTraverse(directory).readFile(filename)
37     else:
38         if hasattr(aq_base(resource), 'GET'):
39             # for FileResource
40             return resource.GET()
41         else:
42             # any BrowserView
43             return resource()
44 
45 
46 def write_js(context, folder, meta_bundle):
47     registry = getUtility(IRegistry)
48     resources = []
49 
50     # default resources
51     if meta_bundle == 'default' and registry.records.get(
52         'plone.resources/jquery.js'
53     ):
54         resources.append(get_resource(context,
55             registry.records['plone.resources/jquery.js'].value))
56         resources.append(get_resource(context,
57             registry.records['plone.resources.requirejs'].value))
58         resources.append(get_resource(context,
59             registry.records['plone.resources.configjs'].value))
60 
61     # bundles
62     bundles = registry.collectionOfInterface(
63         IBundleRegistry, prefix="plone.bundles", check=False)
64     for bundle in bundles.values():
65         if bundle.merge_with == meta_bundle:
66             resources.append(get_resource(context, bundle.jscompilation))
67 
68     fi = StringIO()
69     for script in resources:
70         fi.write(script + '\n')
71     folder.writeFile(meta_bundle + ".js", fi)
72 
73 
74 def write_css(context, folder, meta_bundle):
75     registry = getUtility(IRegistry)
76     resources = []
77 
78     bundles = registry.collectionOfInterface(
79         IBundleRegistry, prefix="plone.bundles", check=False)
80     for bundle in bundles.values():
81         if bundle.merge_with == meta_bundle:
82             resources.append(get_resource(context, bundle.csscompilation))
83 
84     fi = StringIO()
85     for script in resources:
86         fi.write(script + '\n')
87     folder.writeFile(meta_bundle + ".css", fi)
88 
89 
90 def combine_bundles(context):
91     persistent_directory = queryUtility(IResourceDirectory, name="persistent")
92     if persistent_directory is None:
93         return
94     if OVERRIDE_RESOURCE_DIRECTORY_NAME not in persistent_directory:
95         persistent_directory.makeDirectory(OVERRIDE_RESOURCE_DIRECTORY_NAME)
96     container = persistent_directory[OVERRIDE_RESOURCE_DIRECTORY_NAME]
97     if PRODUCTION_RESOURCE_DIRECTORY not in container:
98         container.makeDirectory(PRODUCTION_RESOURCE_DIRECTORY)
99     production_folder = container[PRODUCTION_RESOURCE_DIRECTORY]
100 
101     # store timestamp
102     fi = StringIO()
103     fi.write(datetime.now().isoformat())
104     production_folder.writeFile("timestamp.txt", fi)
105 
106     # generate new combined bundles
107     write_js(context, production_folder, 'default')
108     write_js(context, production_folder, 'logged-in')
109     write_css(context, production_folder, 'default')
110     write_css(context, production_folder, 'logged-in')
111
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/Products/CMFPlone/resources/browser/combine.py b/Products/CMFPlone/resources/browser/combine.py
--- a/Products/CMFPlone/resources/browser/combine.py
+++ b/Products/CMFPlone/resources/browser/combine.py
@@ -1,3 +1,4 @@
+import re
 from zExceptions import NotFound
 from Acquisition import aq_base
 from datetime import datetime
@@ -79,7 +80,15 @@
         IBundleRegistry, prefix="plone.bundles", check=False)
     for bundle in bundles.values():
         if bundle.merge_with == meta_bundle:
-            resources.append(get_resource(context, bundle.csscompilation))
+            css = get_resource(context, bundle.csscompilation)
+            # Preserve relative urls:
+            # we prefix with '../'' any url not starting with '/'
+            # or http: or data:
+            css = re.sub(
+                r"""(url\(['"]?(?!['"]?([a-z]+:|\/)))""",
+                r'\1../',
+                css)
+            resources.append(css)
 
     fi = StringIO()
     for script in resources:

{"golden_diff": "diff --git a/Products/CMFPlone/resources/browser/combine.py b/Products/CMFPlone/resources/browser/combine.py\n--- a/Products/CMFPlone/resources/browser/combine.py\n+++ b/Products/CMFPlone/resources/browser/combine.py\n@@ -1,3 +1,4 @@\n+import re\n from zExceptions import NotFound\n from Acquisition import aq_base\n from datetime import datetime\n@@ -79,7 +80,15 @@\n         IBundleRegistry, prefix=\"plone.bundles\", check=False)\n     for bundle in bundles.values():\n         if bundle.merge_with == meta_bundle:\n-            resources.append(get_resource(context, bundle.csscompilation))\n+            css = get_resource(context, bundle.csscompilation)\n+            # Preserve relative urls:\n+            # we prefix with '../'' any url not starting with '/'\n+            # or http: or data:\n+            css = re.sub(\n+                r\"\"\"(url\\(['\"]?(?!['\"]?([a-z]+:|\\/)))\"\"\",\n+                r'\\1../',\n+                css)\n+            resources.append(css)\n \n     fi = StringIO()\n     for script in resources:\n", "issue": "CSS bundles generation breaks background images relative urls\nThis is a bug related to PR #1300.\n\n", "before_files": [{"content": "from zExceptions import NotFound\nfrom Acquisition import aq_base\nfrom datetime import datetime\nfrom plone.registry.interfaces import IRegistry\nfrom plone.resource.file import FilesystemFile\nfrom plone.resource.interfaces import IResourceDirectory\nfrom Products.CMFPlone.interfaces import IBundleRegistry\nfrom Products.CMFPlone.interfaces.resources import (\n    OVERRIDE_RESOURCE_DIRECTORY_NAME,\n)\nfrom StringIO import StringIO\nfrom zope.component import getUtility\nfrom zope.component import queryUtility\n\nPRODUCTION_RESOURCE_DIRECTORY = \"production\"\n\n\ndef get_production_resource_directory():\n    persistent_directory = queryUtility(IResourceDirectory, name=\"persistent\")\n    if persistent_directory is None:\n        return ''\n    container = persistent_directory[OVERRIDE_RESOURCE_DIRECTORY_NAME]\n    try:\n        production_folder = container[PRODUCTION_RESOURCE_DIRECTORY]\n    except NotFound:\n        return \"%s/++unique++1\" % PRODUCTION_RESOURCE_DIRECTORY\n    timestamp = production_folder.readFile('timestamp.txt')\n    return \"%s/++unique++%s\" % (\n        PRODUCTION_RESOURCE_DIRECTORY, timestamp)\n\n\ndef get_resource(context, path):\n    resource = context.unrestrictedTraverse(path)\n    if isinstance(resource, FilesystemFile):\n        (directory, sep, filename) = path.rpartition('/')\n        return context.unrestrictedTraverse(directory).readFile(filename)\n    else:\n        if hasattr(aq_base(resource), 'GET'):\n            # for FileResource\n            return resource.GET()\n        else:\n            # any BrowserView\n            return resource()\n\n\ndef write_js(context, folder, meta_bundle):\n    registry = getUtility(IRegistry)\n    resources = []\n\n    # default resources\n    if meta_bundle == 'default' and registry.records.get(\n        'plone.resources/jquery.js'\n    ):\n        resources.append(get_resource(context,\n            registry.records['plone.resources/jquery.js'].value))\n        resources.append(get_resource(context,\n            registry.records['plone.resources.requirejs'].value))\n        resources.append(get_resource(context,\n            registry.records['plone.resources.configjs'].value))\n\n    # bundles\n    bundles = registry.collectionOfInterface(\n        IBundleRegistry, prefix=\"plone.bundles\", check=False)\n    for bundle in bundles.values():\n        if bundle.merge_with == meta_bundle:\n            resources.append(get_resource(context, bundle.jscompilation))\n\n    fi = StringIO()\n    for script in resources:\n        fi.write(script + '\\n')\n    folder.writeFile(meta_bundle + \".js\", fi)\n\n\ndef write_css(context, folder, meta_bundle):\n    registry = getUtility(IRegistry)\n    resources = []\n\n    bundles = registry.collectionOfInterface(\n        IBundleRegistry, prefix=\"plone.bundles\", check=False)\n    for bundle in bundles.values():\n        if bundle.merge_with == meta_bundle:\n            resources.append(get_resource(context, bundle.csscompilation))\n\n    fi = StringIO()\n    for script in resources:\n        fi.write(script + '\\n')\n    folder.writeFile(meta_bundle + \".css\", fi)\n\n\ndef combine_bundles(context):\n    persistent_directory = queryUtility(IResourceDirectory, name=\"persistent\")\n    if persistent_directory is None:\n        return\n    if OVERRIDE_RESOURCE_DIRECTORY_NAME not in persistent_directory:\n        persistent_directory.makeDirectory(OVERRIDE_RESOURCE_DIRECTORY_NAME)\n    container = persistent_directory[OVERRIDE_RESOURCE_DIRECTORY_NAME]\n    if PRODUCTION_RESOURCE_DIRECTORY not in container:\n        container.makeDirectory(PRODUCTION_RESOURCE_DIRECTORY)\n    production_folder = container[PRODUCTION_RESOURCE_DIRECTORY]\n\n    # store timestamp\n    fi = StringIO()\n    fi.write(datetime.now().isoformat())\n    production_folder.writeFile(\"timestamp.txt\", fi)\n\n    # generate new combined bundles\n    write_js(context, production_folder, 'default')\n    write_js(context, production_folder, 'logged-in')\n    write_css(context, production_folder, 'default')\n    write_css(context, production_folder, 'logged-in')\n", "path": "Products/CMFPlone/resources/browser/combine.py"}], "after_files": [{"content": "import re\nfrom zExceptions import NotFound\nfrom Acquisition import aq_base\nfrom datetime import datetime\nfrom plone.registry.interfaces import IRegistry\nfrom plone.resource.file import FilesystemFile\nfrom plone.resource.interfaces import IResourceDirectory\nfrom Products.CMFPlone.interfaces import IBundleRegistry\nfrom Products.CMFPlone.interfaces.resources import (\n    OVERRIDE_RESOURCE_DIRECTORY_NAME,\n)\nfrom StringIO import StringIO\nfrom zope.component import getUtility\nfrom zope.component import queryUtility\n\nPRODUCTION_RESOURCE_DIRECTORY = \"production\"\n\n\ndef get_production_resource_directory():\n    persistent_directory = queryUtility(IResourceDirectory, name=\"persistent\")\n    if persistent_directory is None:\n        return ''\n    container = persistent_directory[OVERRIDE_RESOURCE_DIRECTORY_NAME]\n    try:\n        production_folder = container[PRODUCTION_RESOURCE_DIRECTORY]\n    except NotFound:\n        return \"%s/++unique++1\" % PRODUCTION_RESOURCE_DIRECTORY\n    timestamp = production_folder.readFile('timestamp.txt')\n    return \"%s/++unique++%s\" % (\n        PRODUCTION_RESOURCE_DIRECTORY, timestamp)\n\n\ndef get_resource(context, path):\n    resource = context.unrestrictedTraverse(path)\n    if isinstance(resource, FilesystemFile):\n        (directory, sep, filename) = path.rpartition('/')\n        return context.unrestrictedTraverse(directory).readFile(filename)\n    else:\n        if hasattr(aq_base(resource), 'GET'):\n            # for FileResource\n            return resource.GET()\n        else:\n            # any BrowserView\n            return resource()\n\n\ndef write_js(context, folder, meta_bundle):\n    registry = getUtility(IRegistry)\n    resources = []\n\n    # default resources\n    if meta_bundle == 'default' and registry.records.get(\n        'plone.resources/jquery.js'\n    ):\n        resources.append(get_resource(context,\n            registry.records['plone.resources/jquery.js'].value))\n        resources.append(get_resource(context,\n            registry.records['plone.resources.requirejs'].value))\n        resources.append(get_resource(context,\n            registry.records['plone.resources.configjs'].value))\n\n    # bundles\n    bundles = registry.collectionOfInterface(\n        IBundleRegistry, prefix=\"plone.bundles\", check=False)\n    for bundle in bundles.values():\n        if bundle.merge_with == meta_bundle:\n            resources.append(get_resource(context, bundle.jscompilation))\n\n    fi = StringIO()\n    for script in resources:\n        fi.write(script + '\\n')\n    folder.writeFile(meta_bundle + \".js\", fi)\n\n\ndef write_css(context, folder, meta_bundle):\n    registry = getUtility(IRegistry)\n    resources = []\n\n    bundles = registry.collectionOfInterface(\n        IBundleRegistry, prefix=\"plone.bundles\", check=False)\n    for bundle in bundles.values():\n        if bundle.merge_with == meta_bundle:\n            css = get_resource(context, bundle.csscompilation)\n            # Preserve relative urls:\n            # we prefix with '../'' any url not starting with '/'\n            # or http: or data:\n            css = re.sub(\n                r\"\"\"(url\\(['\"]?(?!['\"]?([a-z]+:|\\/)))\"\"\",\n                r'\\1../',\n                css)\n            resources.append(css)\n\n    fi = StringIO()\n    for script in resources:\n        fi.write(script + '\\n')\n    folder.writeFile(meta_bundle + \".css\", fi)\n\n\ndef combine_bundles(context):\n    persistent_directory = queryUtility(IResourceDirectory, name=\"persistent\")\n    if persistent_directory is None:\n        return\n    if OVERRIDE_RESOURCE_DIRECTORY_NAME not in persistent_directory:\n        persistent_directory.makeDirectory(OVERRIDE_RESOURCE_DIRECTORY_NAME)\n    container = persistent_directory[OVERRIDE_RESOURCE_DIRECTORY_NAME]\n    if PRODUCTION_RESOURCE_DIRECTORY not in container:\n        container.makeDirectory(PRODUCTION_RESOURCE_DIRECTORY)\n    production_folder = container[PRODUCTION_RESOURCE_DIRECTORY]\n\n    # store timestamp\n    fi = StringIO()\n    fi.write(datetime.now().isoformat())\n    production_folder.writeFile(\"timestamp.txt\", fi)\n\n    # generate new combined bundles\n    write_js(context, production_folder, 'default')\n    write_js(context, production_folder, 'logged-in')\n    write_css(context, production_folder, 'default')\n    write_css(context, production_folder, 'logged-in')\n", "path": "Products/CMFPlone/resources/browser/combine.py"}]}