mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-24 10:37:23 +00:00
Fix for #2309 (long unicode filenames could get to long)
This commit is contained in:
parent
7861f8a89a
commit
834edadc28
10
cps.py
10
cps.py
@ -16,11 +16,11 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
try:
|
||||
from gevent import monkey
|
||||
monkey.patch_all()
|
||||
except ImportError:
|
||||
pass
|
||||
#try:
|
||||
#from gevent import monkey
|
||||
#monkey.patch_all()
|
||||
#except ImportError:
|
||||
# pass
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
import os
|
||||
import io
|
||||
import sys
|
||||
import mimetypes
|
||||
import re
|
||||
import shutil
|
||||
@ -224,11 +225,23 @@ def send_mail(book_id, book_format, convert, kindle_mail, calibrepath, user_id):
|
||||
return _(u"The requested file could not be read. Maybe wrong permissions?")
|
||||
|
||||
|
||||
def shorten_component(s, by_what):
|
||||
l = len(s)
|
||||
if l < by_what:
|
||||
return s
|
||||
l = (l - by_what)//2
|
||||
if l <= 0:
|
||||
return s
|
||||
return s[:l] + s[-l:]
|
||||
|
||||
|
||||
def get_valid_filename(value, replace_whitespace=True, chars=128):
|
||||
"""
|
||||
Returns the given string converted to a string that can be used for a clean
|
||||
filename. Limits num characters to 128 max.
|
||||
"""
|
||||
|
||||
|
||||
if value[-1:] == u'.':
|
||||
value = value[:-1]+u'_'
|
||||
value = value.replace("/", "_").replace(":", "_").strip('\0')
|
||||
@ -239,7 +252,10 @@ def get_valid_filename(value, replace_whitespace=True, chars=128):
|
||||
value = re.sub(r'[*+:\\\"/<>?]+', u'_', value, flags=re.U)
|
||||
# pipe has to be replaced with comma
|
||||
value = re.sub(r'[|]+', u',', value, flags=re.U)
|
||||
value = value[:chars].strip()
|
||||
|
||||
filename_encoding_for_length = 'utf-16' if sys.platform == "win32" or sys.platform == "darwin" else 'utf-8'
|
||||
value = value.encode(filename_encoding_for_length)[:chars].decode('utf-8', errors='ignore').strip()
|
||||
|
||||
if not value:
|
||||
raise ValueError("Filename cannot be empty")
|
||||
return value
|
||||
|
@ -37,14 +37,14 @@
|
||||
<div class="row">
|
||||
<div class="col-xs-6 col-md-6 col-sm-offset-3" style="margin-top:50px;">
|
||||
|
||||
<p class='text-justify attribute'><strong>Start Time: </strong>2022-03-28 06:40:49</p>
|
||||
<p class='text-justify attribute'><strong>Start Time: </strong>2022-03-28 21:45:14</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-6 col-md-6 col-sm-offset-3">
|
||||
|
||||
<p class='text-justify attribute'><strong>Stop Time: </strong>2022-03-28 12:18:13</p>
|
||||
<p class='text-justify attribute'><strong>Stop Time: </strong>2022-03-29 03:21:52</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@ -1562,11 +1562,11 @@
|
||||
|
||||
|
||||
|
||||
<tr id="su" class="passClass">
|
||||
<tr id="su" class="failClass">
|
||||
<td>TestLoadMetadata</td>
|
||||
<td class="text-center">1</td>
|
||||
<td class="text-center">1</td>
|
||||
<td class="text-center">0</td>
|
||||
<td class="text-center">1</td>
|
||||
<td class="text-center">0</td>
|
||||
<td class="text-center">0</td>
|
||||
<td class="text-center">
|
||||
@ -1576,11 +1576,31 @@
|
||||
|
||||
|
||||
|
||||
<tr id='pt15.1' class='hiddenRow bg-success'>
|
||||
<tr id="ft15.1" class="none bg-danger">
|
||||
<td>
|
||||
<div class='testcase'>TestLoadMetadata - test_load_metadata</div>
|
||||
</td>
|
||||
<td colspan='6' align='center'>PASS</td>
|
||||
<td colspan='6'>
|
||||
<div class="text-center">
|
||||
<a class="popup_link text-center" onfocus='blur()' onclick="showTestDetail('div_ft15.1')">FAIL</a>
|
||||
</div>
|
||||
<!--css div popup start-->
|
||||
<div id="div_ft15.1" class="popup_window test_output" style="display:block;">
|
||||
<div class='close_button pull-right'>
|
||||
<button type="button" class="close" aria-label="Close" onfocus="this.blur();"
|
||||
onclick="document.getElementById('div_ft15.1').style.display='none'"><span
|
||||
aria-hidden="true">×</span></button>
|
||||
</div>
|
||||
<div class="text-left pull-left">
|
||||
<pre class="text-left">Traceback (most recent call last):
|
||||
File "/home/ozzie/Development/calibre-web-test/test/test_edit_books_metadata.py", line 167, in test_load_metadata
|
||||
self.assertGreaterEqual(diff(BytesIO(cover), BytesIO(original_cover), delete_diff_file=True), 0.05)
|
||||
AssertionError: 0.0 not greater than or equal to 0.05</pre>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<!--css div popup end-->
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
@ -4548,8 +4568,8 @@
|
||||
<tr id='total_row' class="text-center bg-grey">
|
||||
<td>Total</td>
|
||||
<td>406</td>
|
||||
<td>400</td>
|
||||
<td>0</td>
|
||||
<td>399</td>
|
||||
<td>1</td>
|
||||
<td>0</td>
|
||||
<td>6</td>
|
||||
<td> </td>
|
||||
@ -4643,6 +4663,12 @@
|
||||
<td>Basic</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>gevent</th>
|
||||
<td>21.12.0</td>
|
||||
<td>Basic</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>greenlet</th>
|
||||
<td>1.1.2</td>
|
||||
@ -4697,12 +4723,6 @@
|
||||
<td>Basic</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>tornado</th>
|
||||
<td>6.1</td>
|
||||
<td>Basic</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Unidecode</th>
|
||||
<td>1.3.4</td>
|
||||
@ -4993,7 +5013,7 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
drawCircle(400, 0, 0, 6);
|
||||
drawCircle(399, 1, 0, 6);
|
||||
showCase(5);
|
||||
</script>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user