Skip to content

Commit

Permalink
LDEV-2736 add removewatermark parameter validation
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed May 23, 2024
1 parent 2486efd commit 396affb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions source/java/src/org/lucee/extension/pdf/tag/PDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,11 @@ private void doActionRemoveWatermark() throws PageException, IOException, Docume
if (destination != null && destination.exists() && !overwrite)
throw engine.getExceptionUtil().createApplicationException("Destination PDF file [" + destination + "] already exists");


if (destination == null && name == null) throw engine.getExceptionUtil().createApplicationException("One of the following attributes [destination, name] is required");

if (destination != null && name != null) throw engine.getExceptionUtil().createApplicationException("Both attributes [destination, name] cannot be defined at the same time");

BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
g.setBackground(Color.BLACK);
Expand Down
7 changes: 6 additions & 1 deletion tests/LDEV2736.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="pdf" {

function run( testResults , testBox ) {
describe( "Testcase for LDEV-2736", function() {
it( title="cfpdf - removewatermark didn't work", body = function( currentSpec ) {
it( title="cfpdf - removewatermark check required params", body = function( currentSpec ) {
pdf action="addwatermark" source="#variables.dir#/main.pdf" copyFrom="#variables.dir#/copyFrom.pdf" name="local.name";

expect( function(){
pdf action="removewatermark" source="#variables.dir#/main.pdf"; //needs name or destination
}).toThrow();

});

it( title="cfpdf - removewatermark didn't work", body = function( currentSpec ) {
pdf action="addwatermark" source="#variables.dir#/main.pdf" copyFrom="#variables.dir#/copyFrom.pdf" name="local.name";

pdf action="removewatermark" source="#variables.dir#/main.pdf" name="local.out";
expect( isPDFObject( out ) ).toBeTrue();

Expand Down

0 comments on commit 396affb

Please sign in to comment.