Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Read .lua scripts and .css style sheets as plain text (#388, #368)

cre8ive-marketing476c0aa425af
diff --git a/src/Filee.Core/Formats/FormatRegistry.cs b/src/Filee.Core/Formats/FormatRegistry.cs
index 1ec46736..14bb5bce 100644
--- a/src/Filee.Core/Formats/FormatRegistry.cs
+++ b/src/Filee.Core/Formats/FormatRegistry.cs
@@ -134,8 +134,9 @@ public static class FormatRegistry
new("sda", "SDA", FormatCategory.Presentation, ["sda", "sdd"], Writable: false),
// Plain text / markup
- // Text logs and source/proxy scripts are read as plain text, never executed (issues #273, #284, #254).
- new("txt", "TXT", FormatCategory.Text, ["txt", "log", "py", "pac", "bat", "command"]),
+ // Text logs, source/proxy scripts and style sheets are read as plain text, never executed (issues #273, #284, #254,
+ // #388, #368).
+ new("txt", "TXT", FormatCategory.Text, ["txt", "log", "py", "pac", "bat", "command", "lua", "css"]),
new("md", "Markdown", FormatCategory.Text, ["md", "markdown"]),
new("html", "HTML", FormatCategory.Text, ["html", "htm", "xhtml"]),
// A web page saved with its pictures in one MIME file (Chrome, Edge, Word); read as the page it holds.
diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.cs
index 4f488dcb..3df95d28 100644
--- a/src/Filee.Core/Settings/AppSettings.cs
+++ b/src/Filee.Core/Settings/AppSettings.cs
@@ -112,7 +112,7 @@ public sealed class DonutSettings
public sealed class AppSettings
{
/// <summary>Current schema version. Increase when the format changes and add a migration.</summary>
- public const int CurrentSchemaVersion = 32;
+ public const int CurrentSchemaVersion = 33;
public int SchemaVersion { get; set; } = CurrentSchemaVersion;
diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.cs
index 7aff0c84..1dbddd84 100644
--- a/src/Filee.Core/Settings/UserDataStore.cs
+++ b/src/Filee.Core/Settings/UserDataStore.cs
@@ -750,6 +750,9 @@ internal static class SettingsMigrations
// v32: logs and script source, Video CD DAT and Workbench archives learn their donuts; custom claims stay put.
if (from < 32)
changed |= LearnExtensions(profiles, out _, ["log", "py", "pac", "bat", "command", "dat", "wbpz"]);
+ // v33: Lua scripts and CSS style sheets learn the text donut; custom claims stay put.
+ if (from < 33)
+ changed |= LearnExtensions(profiles, out _, ["lua", "css"]);
return changed;
}
diff --git a/tests/Filee.Core.Tests/ScriptTextTests.cs b/tests/Filee.Core.Tests/ScriptTextTests.cs
new file mode 100644
index 00000000..0839cf28
--- /dev/null
+++ b/tests/Filee.Core.Tests/ScriptTextTests.cs
@@ -0,0 +1,33 @@
+// Lua scripts and CSS style sheets are plain text (issues #388, #368): recognised, and learnt by existing text donuts.
+
+using Filee.Core.Formats;
+using Filee.Core.Presets;
+using Filee.Core.Profiles;
+using Filee.Core.Settings;
+
+namespace Filee.Core.Tests;
+
+public class ScriptTextTests
+{
+ [Theory]
+ [InlineData("init.lua")]
+ [InlineData("site.css")]
+ public void Scripts_and_style_sheets_are_text(string name) => Assert.Equal("txt", FormatRegistry.Detect(name)?.Id);
+
+ [Fact]
+ public void Version_32_text_donuts_learn_them_without_taking_custom_claims()
+ {
+ var presets = BuiltInData.CreatePresets();
+ var profiles = BuiltInData.CreateProfiles();
+ foreach (var profile in profiles)
+ profile.Extensions.RemoveAll(e => e is "lua" or "css");
+ profiles.Insert(0, new ToolbarProfile { Id = "my-web", Name = "Web", Extensions = ["css"] });
+
+ Assert.True(SettingsMigrations.ApplyToLibrary(32, presets, profiles));
+
+ var text = profiles.Single(p => p.Id == "text").Extensions;
+ Assert.Contains("lua", text);
+ Assert.DoesNotContain("css", text); // the user's own donut has it
+ Assert.False(SettingsMigrations.ApplyToLibrary(32, presets, profiles));
+ }
+}
diff --git a/tests/Filee.Engines.Tests/ScriptTextTests.cs b/tests/Filee.Engines.Tests/ScriptTextTests.cs
new file mode 100644
index 00000000..80c651c1
--- /dev/null
+++ b/tests/Filee.Engines.Tests/ScriptTextTests.cs
@@ -0,0 +1,27 @@
+// Lua scripts and CSS style sheets (issues #388, #368) become a PDF of their text, never run.
+
+using Filee.Core.Conversion;
+using Filee.Core.Presets;
+using Filee.Engines.Pdf;
+
+namespace Filee.Engines.Tests;
+
+public class ScriptTextTests(EngineFixture fx) : IClassFixture<EngineFixture>
+{
+ [Theory]
+ [InlineData("site.css", "body { color: #1d9e75; }")]
+ [InlineData("init.lua", "local greeting = \"hello\" print(greeting)")]
+ public async Task The_code_becomes_a_pdf_of_its_text(string name, string code)
+ {
+ var available = fx.Converters.Where(c => fx.Catalog.StatusOf(c).IsAvailable).Select(c => c.Id).ToHashSet();
+ Assert.SkipUnless(available.Contains("rhwp") || available.Contains("libreoffice"), "neither rhwp nor LibreOffice is available");
+ var path = Path.Combine(fx.NewFolder(), name);
+ await File.WriteAllTextAsync(path, code, TestContext.Current.CancellationToken);
+
+ var job = await fx.ConvertAsync([path], new Preset { TargetFormat = "pdf" });
+
+ Assert.True(job.State == JobState.Completed, string.Join("; ", job.Files.Select(f => $"{f.ErrorKey} {f.ErrorDetail}")));
+ var text = PdfDocumentReader.PlainText(PdfDocumentReader.ReadText(Assert.Single(job.Outputs)));
+ Assert.Contains(code.Split(' ')[1], text);
+ }
+}